Windows (only?) Null Buffer Length
Found someone else on SO posting about this so I thought I'd make an issue here. For those working in Windows or deploying to Azure Web Apps, we're all running into a null reference error determining the length of the write buffer here:
string_decoder.js:66
var buflen = buffer.length;
TypeError: Cannot read property 'length' of null
at StringDecoder.write (string_decoder.js:66:22)
at Interface._normalWrite (readline.js:319:30)
at Interface.write (readline.js:310:49)
at message.converse.makeActionCallback.runActions.interactive.rl.on [as interactive] (D:\R&D\witai\node_modules\node-wit\lib\wit.js:286:13)
at Object.<anonymous> (\witai\node_modules\node-wit\examples\template.js:29:8)
http://stackoverflow.com/questions/37266010/wit-ai-example-code-error-null-buffer-length
This can be reproduced on a Mac/Linux machine if you install Visual Studio Code and run the debugger with this as your launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy",
"--harmony"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 3000,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
For what it's worth this can be fixed by updating to this:
this.rl.on('line', ((line) => {
const msg = line.trim();
this.runActions(
sessionId,
msg,
this.context,
(error, context) => {
if (error) {
l.error(error);
} else {
this.context = context;
}
this.rl.prompt();
this.rl.write('', {ctrl: true, name: 'e'});
},
steps
);
}).bind(this));
Just replace the null with an empty string. Seems trivial, I'm not sure why this is happening. NPM version 3.8.1, "node-wit": "^3.3.0", "node": "0.12.6"
Thanks for the workaround!! I was searching for this...
I've got the same problem when trying to run in Meteor shell which is similar to node shell. I'm using ubuntu 14.04 server
Here is my wit client
> WitAPI.wit
Wit {
config:
{ accessToken: 'xxxxxxxxxxxxxxxx',
actions:
{ send: [Function: send],
clearContext: [Function: clearContext],
clearContextAndSession: [Function: clearContextAndSession],
addExpenseInit: [Function: addExpenseInit],
addExpenseEnoughContext: [Function: addExpenseEnoughContext],
addExpenseMissingAmount: [Function: addExpenseMissingAmount],
addExpenseMissingDesc: [Function: addExpenseMissingDesc],
addExpenseFinalize: [Function: addExpenseFinalize],
transactionChangeOptions: [Function: transactionChangeOptions],
transactionChangeAskDate: [Function: transactionChangeAskDate],
transactionChangeAskAmount: [Function: transactionChangeAskAmount],
transactionChangeAskDesc: [Function: transactionChangeAskDesc],
receivedMisc: [Function: receivedMisc],
replyMisc: [Function: replyMisc],
setLimitInit: [Function: setLimitInit],
askExpenseLimitAmount: [Function: askExpenseLimitAmount],
setLimitEnoughContext: [Function: setLimitEnoughContext],
setLimit: [Function: setLimit],
updateTransaction: [Function: updateTransaction],
removeTransaction: [Function: removeTransaction],
listTransaction: [Function: listTransaction],
reportTransaction: [Function: reportTransaction],
removeLimit: [Function: removeLimit],
showLimit: [Function: showLimit],
setLanguage: [Function: setLanguage],
changeLanguage: [Function: changeLanguage],
offerHelp: [Function: offerHelp],
showHelpMenu: [Function: showHelpMenu] },
witURL: 'https://api.wit.ai',
apiVersion: '20160516',
headers:
{ Authorization: 'Bearer xxxxxxxxxxxx',
Accept: 'application/vnd.wit.20160516+json',
'Content-Type': 'application/json' },
logger:
Logger {
level: 'info',
debug: [Function: noop],
info: [Function: bound bound ],
warn: [Function: bound bound ],
error: [Function: bound bound ] } },
_sessions: {},
message: [Function],
converse: [Function],
runActions: [Function] }
When I try to run in interactive mode
> interactive(WitAPI.wit)
string_decoder.js:66
var buflen = buffer.length;
^
TypeError: Cannot read property 'length' of null
at [object Object].StringDecoder.write (string_decoder.js:66:22)
at Interface._normalWrite (readline.js:320:30)
at Interface.write (readline.js:311:49)
at prompt (/home/bitnami/sn-webapp/node_modules/node-wit/lib/interactive.js:24:8)
at module.exports (/home/bitnami/sn-webapp/node_modules/node-wit/lib/interactive.js:26:3)
at repl:1:-61
at packages/shell-server/shell-server.js:458:25
at /home/bitnami/.meteor/packages/promise/.0.8.8.1jn8psc++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:32:39
>