Comments (8)
Ok I put this in my TODO
from arsenal.
Something like that ?
_parse(data, callback) {
const version = data.readInt8(0);
const pbMsgLen = data.readInt32BE(1);
const chunkLen = data.readInt32BE(5);
if (version !== getVersion()) {
return callback(new Error('Version Failure'));
}
try {
this._cmd = protoBuild.Message.decode(data.slice(9, 9 + pbMsgLen));
this.setProtobuf(protoBuild.Command.decode(this._cmd.commandBytes));
} catch (e) {
if (e.decoded) {
this.setProtobuf(e.decoded);
} else {
return callback(new Error('Error in decode' + e));
}
}
this.setChunk(data.slice(pbMsgLen + 9, chunkLen + pbMsgLen + 9));
if (this.getChunkSize() !== chunkLen) {
return callback(new Error('data error - different len'));
}
if (this._cmd.authType === 1 &&
!this.hmacIntegrity(this.getSlice(this._cmd.hmacAuth.hmac)))
return callback(new Error('Hmac fail'));
return callback(null);
}
with a constructor like this :
constructor(input, callback) {
/*
* From Kinetic official documentation, a Kinetic Protocol Data Unit
* (PDU) is composed of:
* - message -- a Protocol Buffer (protobuf) message, containing
* operation metadata & key-value metadata,
* - chunk -- the value to store/read.
*/
this._message = undefined;
this._chunk = undefined;
if (input !== undefined) {
if (!Buffer.isBuffer(input))
return callback(new Error("input is not a buffer"));
this._parse(input, (err) => {
if (err){
return callback(new Error("could not parse input buffer (" + err + ")"));
} else {
return callback(null, this);
}
});
}
}
from arsenal.
Since both _parse
and constructor
are synchronous, I wouldn't use callbacks here.
Instead, they could throw exceptions, explicitely say it their jsdoc, and all code calling them should check for exceptions.
Example:
_parse(data) {
if (version !== getVersion()) {
const err = new Error('Version Failure');
err.badVersion = true;
throw err;
}
}
Client code:
try {
const pdu = new Kinetic.PDU(new Buffer("sdkfljsdf"));
} catch (e) {
if (e.badVersion) {
log.error("bad version!");
}
}
from arsenal.
Okok
And for send ? I tried something like that but i'm not really good on error handling, so I don't really know what is the best way
try {
if (this.getChunk() !== undefined)
sock.write(Buffer.concat(
[pduHeader, this._message.toBuffer(), this.getChunk()]));
else
sock.write(Buffer.concat([pduHeader,
this._message.toBuffer()]));
} catch (e) {
return callback(e);
}
return callback(null);
I did this before, I just forgot to update my comment X)
from arsenal.
I tried to do a better error throwing/handling on the branch dev/CLEANUP/error_return
There are some tests on the branch
from arsenal.
Thanks @AntoninCoulibaly. The branch you created brings lots of enhancements, can you create a pull request for it? I have a few comments to make, but mostly 👍
from arsenal.
Ok no problem I will
from arsenal.
Closing, since this is not relevant in this repo anymore.
from arsenal.
Related Issues (20)
- multiple high and critical issues in `yarn audit` HOT 1
- empty/invalid/unredable/none Date header: errors incompatible with AWS
- invalid amz-date header: errors incompatible with AWS
- incorrect authorization header: errors incompatible with AWS
- authv4 sort query params HOT 1
- COMPAT: Increase Signature V2 Expires param
- COMPAT: return AccessDenied if Date before epochTime (01/01/1970) HOT 4
- callApiMethod in routes is not defined
- Error messages should not have periods
- Review of https://github.com/scality/Arsenal/pull/2152
- Re-review of https://github.com/scality/Arsenal/pull/2152
- Policy evaluation, action should be case insensitive
- Tests for #240 HOT 1
- delimiter.js maxKeys==0 param issue HOT 4
- Logs are broken HOT 6
- Exception occurs when using v4 authentication with certain query parameters
- Unbalanced log
- non monotonic clock used in version ID generation
- Action required: Greenkeeper could not be activated 🚨
- Invalid Greenkeeper configuration file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arsenal.