Comparing version 2.0.0 to 2.1.0
@@ -23,5 +23,3 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var assert = require('assert'); | ||
var inherits = require('util').inherits; | ||
var TypedError = require('error/typed'); | ||
var ThriftStruct = require('./struct').ThriftStruct; | ||
@@ -38,40 +36,32 @@ | ||
ThriftException.prototype.compile = function compile(def) { | ||
ThriftException.prototype.compile = function compile(def, thrift) { | ||
var self = this; | ||
ThriftStruct.prototype.compile.call(self, def); | ||
assert(def.annotations, | ||
'annotations required for exception: ' + self.name); | ||
assert(def.annotations.type, | ||
'exceptions must have a type annotation: ' + self.name); | ||
assert(typeof def.annotations.type === 'string', | ||
'type annotation must be a string: ' + self.name); | ||
assert(typeof def.annotations.message === 'string', | ||
'message annotation must be a string: ' + self.name); | ||
self.type = def.annotations.type; | ||
self.message = def.annotations.message; | ||
}; | ||
ThriftException.prototype.createConstructor = | ||
function createConstructor(name, fieldNames) { | ||
ThriftException.prototype.create = function create() { | ||
var self = this; | ||
var declaration = { | ||
type: self.type, | ||
message: self.message | ||
}; | ||
for (var index = 0; index < fieldNames.length; index++) { | ||
var fieldName = fieldNames[index]; | ||
declaration[fieldName] = null; | ||
} | ||
return TypedError(declaration); | ||
}; | ||
var error = new Error(''); | ||
ThriftException.prototype.create = function create() { | ||
return {}; | ||
error.name = 'ThriftException'; | ||
self.Constructor.call(error); | ||
return error; | ||
}; | ||
ThriftException.prototype.finalize = function finalize(struct) { | ||
var self = this; | ||
return self.Constructor(struct); | ||
ThriftException.prototype.set = function set(error, key, value) { | ||
if (key === 'type') { | ||
// Re-define writable to work around v8ism | ||
Object.defineProperty(error, 'type', { | ||
value: value, | ||
enumerable: true, | ||
writable: true, | ||
configurable: true | ||
}); | ||
} | ||
error[key] = value; | ||
}; | ||
module.exports.ThriftException = ThriftException; |
{ | ||
"name": "thriftrw", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "thrift encoding/decoding using bufrw", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -32,5 +32,9 @@ // Copyright (c) 2015 Uber Technologies, Inc. | ||
var err = new Error('Bogus name: Voldemort'); | ||
err.name = 'ThriftException'; | ||
err.bogusName = 'Voldemort'; | ||
test('Exception RW', testRW.cases(thrift.BogusNameError.rw, [ | ||
[thrift.BogusNameError({bogusName: 'Voldemort'}), [ | ||
[err, [ | ||
0x0b, // typeid:1 -- 11, STRING | ||
@@ -41,2 +45,10 @@ 0x00, 0x01, // id:2 -- 1, bogusName | ||
0x6d, 0x6f, 0x72, 0x74, // | ||
0x0b, // typeid:1 -- 11, STRING | ||
0x00, 0x02, // id:2 -- 2, message | ||
0x00, 0x00, 0x00, 0x15, // lenght:4 -- 21 | ||
0x42, 0x6f, 0x67, 0x75, 0x73, | ||
0x20, 0x6e, 0x61, 0x6d, 0x65, | ||
0x3a, 0x20, 0x56, 0x6f, 0x6c, | ||
0x64, 0x65, 0x6d, 0x6f, 0x72, | ||
0x74, | ||
0x00 // typeid:1 -- 0, STOP | ||
@@ -46,1 +58,31 @@ ]] | ||
])); | ||
var err2 = new Error('Bogus name: Voldemort'); | ||
err2.name = 'ThriftException'; | ||
Object.defineProperty(err2, 'type', { | ||
value: 'Voldemort', | ||
configurable: true, | ||
enumerable: true, | ||
writable: true | ||
}); | ||
test('Exception RW with type', testRW.cases(thrift.BogusWithType.rw, [ | ||
[err2, [ | ||
0x0b, // typeid:1 -- 11, STRING | ||
0x00, 0x01, // id:2 -- 1, type | ||
0x00, 0x00, 0x00, 0x09, // length:4 -- 9 | ||
0x56, 0x6f, 0x6c, 0x64, 0x65, // -- 'Voldemort' | ||
0x6d, 0x6f, 0x72, 0x74, // | ||
0x0b, // typeid:1 -- 11, STRING | ||
0x00, 0x02, // id:2 -- 2, message | ||
0x00, 0x00, 0x00, 0x15, // lenght:4 -- 21 | ||
0x42, 0x6f, 0x67, 0x75, 0x73, | ||
0x20, 0x6e, 0x61, 0x6d, 0x65, | ||
0x3a, 0x20, 0x56, 0x6f, 0x6c, | ||
0x64, 0x65, 0x6d, 0x6f, 0x72, | ||
0x74, | ||
0x00 // typeid:1 -- 0, STOP | ||
]] | ||
])); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
329901
5900