Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli works, node version gives error #31

Open
nick-lehmann opened this issue Jan 12, 2017 · 0 comments
Open

Cli works, node version gives error #31

nick-lehmann opened this issue Jan 12, 2017 · 0 comments

Comments

@nick-lehmann
Copy link

I try to print out large responses from an API pretty to the console. When using console.log(prettyjson.render(body)) I will get the normal output. When I save the response to a file and invoke the CLI version onto it, it works very fine (great job, still big thanks to you!).

I have decided to only save a smaller part of it and try it out, just to make sure it is not because of the size of the string. I have also linted it, but the JSON is valid. The excerpt is

{"sync_token":"CmkX2VYduo943FnaTQiSIah7TIcYViURLz-JtotQTX5l48Q4K_N65dcsj2XLkoZkUoBgTYT3pWH9cgdtGTo3iLDf4aVRIIclBCUaMuYVBqjK4KQ","temp_id_mapping":{},"labels":[{"item_order":8,"is_deleted":0,"name":"Bassam-Coles","color":6,"id":180356},{"item_order":6,"is_deleted":0,"name":"Computer_Science","color":7,"id":179952},{"item_order":1,"is_deleted":0,"name":"English","color":7,"id":179946},{"item_order":2,"is_deleted":0,"name":"German","color":7,"id":179947},{"item_order":12,"is_deleted":0,"name":"Hassan","color":6,"id":180363},{"item_order":4,"is_deleted":0,"name":"History","color":7,"id":179950},{"item_order":10,"is_deleted":0,"name":"Hoffmann","color":6,"id":180357},{"item_order":13,"is_deleted":0,"name":"Kr\u00fcger","color":6,"id":180364},{"item_order":16,"is_deleted":0,"name":"Mama","color":7,"id":703291},{"item_order":3,"is_deleted":0,"name":"Math","color":7,"id":179948},{"item_order":5,"is_deleted":0,"name":"Physics","color":7,"id":179951},{"item_order":11,"is_deleted":0,"name":"Scheibner","color":6,"id":180359},{"item_order":9,"is_deleted":0,"name":"Scott","color":6,"id":664961},{"item_order":15,"is_deleted":0,"name":"Tao","color":7,"id":198571},{"item_order":7,"is_deleted":0,"name":"Tok","color":7,"id":664960},{"item_order":14,"is_deleted":0,"name":"waiting","color":0,"id":188154}],"full_sync":true}

When using the following code, I get the error message displayed underneath

var prettyjson = require('prettyjson'),
    fs = require('fs');

var data = fs.readFile('todoistResponse');

var options = {
    noColors: true,
};

console.log(prettyjson.render(data, options));
Nicks-Air:node-todoist-api nicklehmann$ node pretty.js
/Users/nicklehmann/Desktop/node-todoist-api/node_modules/prettyjson/lib/utils.js:16
  Object.getOwnPropertyNames(input).forEach(function(key) {
         ^

TypeError: Cannot convert undefined or null to object
    at Function.getOwnPropertyNames (native)
    at Object.exports.getMaxIndexLength (/Users/nicklehmann/Desktop/node-todoist-api/node_modules/prettyjson/lib/utils.js:16:10)
    at renderToArray (/Users/nicklehmann/Desktop/node-todoist-api/node_modules/prettyjson/lib/prettyjson.js:141:52)
    at Object.render (/Users/nicklehmann/Desktop/node-todoist-api/node_modules/prettyjson/lib/prettyjson.js:210:10)
    at Object.<anonymous> (/Users/nicklehmann/Desktop/node-todoist-api/pretty.js:16:24)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

I would be delighted to hear any advise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant