I seem to be experiencing a node/thrift namespace conflict.
Foo.thrift
...
struct Error {
1: i32 code,
2: string message
}
...
which generates the following file via thrift --gen js:node Foo.thrift (thrift v0.9.0)
Foo_types.js
...
Error = module.exports.Error = function(args) {
this.code = null;
this.message = null;
if (args) {
if (args.code !== undefined) {
this.code = args.code;
}
if (args.message !== undefined) {
this.message = args.message;
}
}
};
Error.prototype = {};
Error.prototype.read = function(input) {
...
I include the module in node
var FooTypes = require('./../gen-nodejs/Foo_types')
I seem to run into a namespace conflict with javascript's Error object
callback(new Error("Couldn't find profile"));
In the callback, it shows that I have an object with code and message vs a plain old JS Error containing "message" even though I didn't ask for FooTypes.Error.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Error
Has anyone else ran into this? How do I make reference to the plain JS Error?
Thanks
You're missing namespace declaration. Try this:
# Foo.thrift file content
namespace js Foo
...
struct Error {
1: i32 code,
2: string message
}
...
Then your thrift object would be Foo.Error.