Last active
December 19, 2015 13:59
-
-
Save nik-kor/5965677 to your computer and use it in GitHub Desktop.
An example of buggy generated code by Thrift 0.8.0 for node.js.
Bug is on 'namespace'-feature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thrift = require('thrift') | |
, Foo = require('./gen-nodejs/test_types.js'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
->thrift -version | |
Thrift version 0.8.0 | |
-> thrift --gen js:node test.thrift #how to generate test_types.js | |
->node client.js | |
/home/nick/dev/ged_projects/admin-panel-gate/gen-nodejs/test_types.js:11 | |
var foo.Bar = module.exports.foo.Bar = function(args) { | |
^ | |
SyntaxError: Unexpected token . | |
at Module._compile (module.js:439:25) | |
at Object.Module._extensions..js (module.js:474:10) | |
at Module.load (module.js:356:32) | |
at Function.Module._load (module.js:312:12) | |
at Module.require (module.js:364:17) | |
at require (module.js:380:17) | |
at Object.<anonymous> (/home/nick/dev/ged_projects/admin-panel-gate/client.js:19:11) | |
at Module._compile (module.js:456:26) | |
at Object.Module._extensions..js (module.js:474:10) | |
at Module.load (module.js:356:32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace js foo | |
struct Bar { | |
1: optional string name; | |
} | |
service Test { | |
Bar read_bar( | |
1: string name, | |
2: i32 some_parameter | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Autogenerated by Thrift Compiler (0.8.0) | |
// | |
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | |
// | |
var Thrift = require('thrift').Thrift; | |
var ttypes = module.exports = {}; | |
if (typeof foo === 'undefined') { | |
foo = {}; | |
} | |
var foo.Bar = module.exports.foo.Bar = function(args) { | |
this.name = null; | |
if (args) { | |
if (args.name !== undefined) { | |
this.name = args.name; | |
} | |
} | |
}; | |
foo.Bar.prototype = {}; | |
foo.Bar.prototype.read = function(input) { | |
input.readStructBegin(); | |
while (true) | |
{ | |
var ret = input.readFieldBegin(); | |
var fname = ret.fname; | |
var ftype = ret.ftype; | |
var fid = ret.fid; | |
if (ftype == Thrift.Type.STOP) { | |
break; | |
} | |
switch (fid) | |
{ | |
case 1: | |
if (ftype == Thrift.Type.STRING) { | |
this.name = input.readString(); | |
} else { | |
input.skip(ftype); | |
} | |
break; | |
case 0: | |
input.skip(ftype); | |
break; | |
default: | |
input.skip(ftype); | |
} | |
input.readFieldEnd(); | |
} | |
input.readStructEnd(); | |
return; | |
}; | |
foo.Bar.prototype.write = function(output) { | |
output.writeStructBegin('Bar'); | |
if (this.name) { | |
output.writeFieldBegin('name', Thrift.Type.STRING, 1); | |
output.writeString(this.name); | |
output.writeFieldEnd(); | |
} | |
output.writeFieldStop(); | |
output.writeStructEnd(); | |
return; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment