{"action":"created","issue":{"url":"https://api.github.com/repos/yargs/yargs/issues/485","repository_url":"https://api.github.com/repos/yargs/yargs","labels_url":"https://api.github.com/repos/yargs/yargs/issues/485/labels{/name}","comments_url":"https://api.github.com/repos/yargs/yargs/issues/485/comments","events_url":"https://api.github.com/repos/yargs/yargs/issues/485/events","html_url":"https://github.com/yargs/yargs/issues/485","id":149814863,"number":485,"title":"Yargs crashes when an invalid package.json is the directory tree.","user":{"login":"avribacki","id":10965374,"avatar_url":"https://avatars.githubusercontent.com/u/10965374?v=3","gravatar_id":"","url":"https://api.github.com/users/avribacki","html_url":"https://github.com/avribacki","followers_url":"https://api.github.com/users/avribacki/followers","following_url":"https://api.github.com/users/avribacki/following{/other_user}","gists_url":"https://api.github.com/users/avribacki/gists{/gist_id}","starred_url":"https://api.github.com/users/avribacki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avribacki/subscriptions","organizations_url":"https://api.github.com/users/avribacki/orgs","repos_url":"https://api.github.com/users/avribacki/repos","events_url":"https://api.github.com/users/avribacki/events{/privacy}","received_events_url":"https://api.github.com/users/avribacki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yargs/yargs/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-04-20T16:10:15Z","updated_at":"2016-05-02T04:45:46Z","closed_at":null,"body":"I'm bundling my application using nexe and it works pretty well except for one particular case.\r\nWhen there's an invalid package.json along the directory from where I'm executing my application, Yargs crashes. If the package.json is valid, it works as normal.\r\n\r\nFor instance, if try to run \"myapp -h\" and there's an empty package.json in the same folder, I get the following error:\r\n\r\n```\r\nnexe.js:102738\r\n                throw jsonErr;\r\n                ^\r\n JSONError: No data, empty input at 1:1 in package.json\r\n^\r\n    at module.exports (nexe.js:102732:17)\r\n    at parse (nexe.js:102684:9)\r\n    at Function.module.exports.sync (nexe.js:102694:9)\r\n    at Function.module.exports.sync (nexe.js:102580:25)\r\n    at parseArgs (nexe.js:107341:37)\r\n    at Object.Yargs.self.showHelp (nexe.js:107192:23)\r\n    at Object.self.fail (nexe.js:99757:35)\r\n    at Object.Yargs.Object.defineProperty.get [as argv] (nexe.js:107331:15)\r\n    at Object.__dirname.1../lib/download.js (nexe.js:48:5)\r\n    at s (nexe.js:1:316)\r\n```\r\n\r\nThis might be a corner case and most likely to happen only when yargs is bundled. Otherwise, it will try to use the package.json of the node package and it will likely be OK.\r\n\r\nOnce bundled, it can run from any location and there might be an invalid package.json lurking around which will produce this crash, which was not obvious to guess the origin.\r\n\r\nYargs seems a perfect fit for command line tools bundled with nexe, that's why I think this deserves a fix.\r\n\r\nWhen I protected the pkgConfig.sync inside parseArgs method, it no longer crashed:\r\n\r\n```\r\n    try {\r\n      options.configuration = pkgConf.sync('yargs', {\r\n        defaults: {},\r\n        cwd: requireMainFilename(require)\r\n      })\r\n    }\r\n    catch (err) {\r\n      options.configuration = {}\r\n    }\r\n```\r\n\r\nNot sure if this is the best solution. I think that the ideal would be to have an option to disable this pkgConf.sync call as, in the context I presented, I don't expect that some package.json lost in my file system to change the app behavior.\r\n"},"comment":{"url":"https://api.github.com/repos/yargs/yargs/issues/comments/216104476","html_url":"https://github.com/yargs/yargs/issues/485#issuecomment-216104476","issue_url":"https://api.github.com/repos/yargs/yargs/issues/485","id":216104476,"user":{"login":"bcoe","id":194609,"avatar_url":"https://avatars.githubusercontent.com/u/194609?v=3","gravatar_id":"","url":"https://api.github.com/users/bcoe","html_url":"https://github.com/bcoe","followers_url":"https://api.github.com/users/bcoe/followers","following_url":"https://api.github.com/users/bcoe/following{/other_user}","gists_url":"https://api.github.com/users/bcoe/gists{/gist_id}","starred_url":"https://api.github.com/users/bcoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcoe/subscriptions","organizations_url":"https://api.github.com/users/bcoe/orgs","repos_url":"https://api.github.com/users/bcoe/repos","events_url":"https://api.github.com/users/bcoe/events{/privacy}","received_events_url":"https://api.github.com/users/bcoe/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T04:45:46Z","updated_at":"2016-05-02T04:45:46Z","body":"a couple thoughts:\r\n\r\n1. I agree with @nexdrew, we let's make it so that package lookups can be disabled in `yargs-parser`.\r\n2. @elas7 just introduced functionality that allows configuration to be passed an arbitrary object (https://github.com/yargs/yargs/pull/480), I think this addresses some of the ideas discussed in this issue.\r\n3. I think that rather than crashing if an invalid package.json is found, we should instead `console.warn()` -- this seems like something we should put a test around."}}