{"action":"created","issue":{"url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/182","repository_url":"https://api.github.com/repos/bcherny/json-schema-to-typescript","labels_url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/182/comments","events_url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/182/events","html_url":"https://github.com/bcherny/json-schema-to-typescript/issues/182","id":354810942,"node_id":"MDU6SXNzdWUzNTQ4MTA5NDI=","number":182,"title":"Parser throws undefined values","user":{"login":"iwan-aucamp-cs","id":30151330,"node_id":"MDQ6VXNlcjMwMTUxMzMw","avatar_url":"https://avatars0.githubusercontent.com/u/30151330?v=4","gravatar_id":"","url":"https://api.github.com/users/iwan-aucamp-cs","html_url":"https://github.com/iwan-aucamp-cs","followers_url":"https://api.github.com/users/iwan-aucamp-cs/followers","following_url":"https://api.github.com/users/iwan-aucamp-cs/following{/other_user}","gists_url":"https://api.github.com/users/iwan-aucamp-cs/gists{/gist_id}","starred_url":"https://api.github.com/users/iwan-aucamp-cs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iwan-aucamp-cs/subscriptions","organizations_url":"https://api.github.com/users/iwan-aucamp-cs/orgs","repos_url":"https://api.github.com/users/iwan-aucamp-cs/repos","events_url":"https://api.github.com/users/iwan-aucamp-cs/events{/privacy}","received_events_url":"https://api.github.com/users/iwan-aucamp-cs/received_events","type":"User","site_admin":false},"labels":[{"id":617680622,"node_id":"MDU6TGFiZWw2MTc2ODA2MjI=","url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/labels/in%20discussion","name":"in discussion","color":"bfdadc","default":false}],"state":"closed","locked":false,"assignee":{"login":"bcherny","id":1761758,"node_id":"MDQ6VXNlcjE3NjE3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false},"assignees":[{"login":"bcherny","id":1761758,"node_id":"MDQ6VXNlcjE3NjE3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2018-08-28T16:33:56Z","updated_at":"2018-09-18T06:50:44Z","closed_at":"2018-09-18T06:50:44Z","author_association":"CONTRIBUTOR","body":"`parser.ts` does the following for some errors:\r\n\r\n```\r\niwana@iwana-nb.concurrent.systems:~/xprojects/github.com/bcherny/json-schema-to-typescript\r\n$ grep 'error' src/parser.ts\r\nimport { error, generateName, log } from './utils'\r\n      throw error('Refs should have been resolved by the resolver!', schema)\r\n  throw error('Supertype must have standalone name!', namedInterface)\r\n```\r\n\r\n`error` is a function which does not return anything - but just logs:\r\n\r\n```javascript\r\nexport function error(...messages: any[]) {\r\n  console.error(whiteBright.bgRedBright('error'), ...messages)\r\n}\r\n```\r\n\r\nAs a consequence, when an error does occur the output is rather messy:\r\n\r\n```\r\n$ json2ts --unreachableDefinitions=true ~/.local/tmp/broken.json\r\nerror Refs should have been resolved by the resolver! { definitions: \r\n   { Something: \r\n      { id: 'Something',\r\n        title: 'The thing that is some',\r\n        type: 'object',\r\n        required: [Array],\r\n        additionalProperties: false,\r\n        properties: [Object],\r\n        description: '' } },\r\n  description: '',\r\n  required: [],\r\n  additionalProperties: true,\r\n  id: 'Broken',\r\n  title: 'The thing that is some',\r\n  type: 'object',\r\n  properties: \r\n   { foo: { type: 'string', title: 'the value of bar' },\r\n     bar: { type: 'string', title: 'the value of foo' } },\r\n  '$ref': '#' }\r\n(node:15375) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'message' of undefined\r\n    at /srv/filesystems/upheigie/projects/github.com/bcherny/json-schema-to-typescript/dist/src/cli.js:38:36\r\n    at Generator.throw (<anonymous>)\r\n    at rejected (/srv/filesystems/upheigie/projects/github.com/bcherny/json-schema-to-typescript/dist/src/cli.js:6:65)\r\n    at <anonymous>\r\n(node:15375) UnhandledPromiseRejectionWarning: Unhandled promise\r\n[broken.txt](https://github.com/bcherny/json-schema-to-typescript/files/2328763/broken.txt)\r\n rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)\r\n(node:15375) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\r\n```\r\n\r\nI'm not sure exactly what the intent is here - but it seems like `throw error` should be `throw Error` instead:\r\n\r\n```diff\r\n$ git diff src/cli.ts src/parser.ts\r\ndiff --git a/src/cli.ts b/src/cli.ts\r\nindex 1a50166..09270b1 100644\r\n--- a/src/cli.ts\r\n+++ b/src/cli.ts\r\n@@ -30,7 +30,12 @@ async function main(argv: minimist.ParsedArgs) {\r\n     const ts = await compile(schema, argIn, argv as Partial<Options>)\r\n     await writeOutput(ts, argOut)\r\n   } catch (e) {\r\n-    process.stderr.write(e.message)\r\n+    if ( process.env.VERBOSE ) {\r\n+      console.error(e)\r\n+    } else {\r\n+      process.stderr.write(e.message)\r\n+      process.stderr.write('\\n')\r\n+    }\r\n     process.exit(1)\r\n   }\r\n \r\ndiff --git a/src/parser.ts b/src/parser.ts\r\nindex feb89a0..3daced2 100644\r\n--- a/src/parser.ts\r\n+++ b/src/parser.ts\r\n@@ -5,7 +5,8 @@ import { Options } from './'\r\n import { typeOfSchema } from './typeOfSchema'\r\n import { AST, hasStandaloneName, T_ANY, T_ANY_ADDITIONAL_PROPERTIES, TInterface, TInterfaceParam, TNamedInterface } from './types/AST'\r\n import { JSONSchema, JSONSchemaWithDefinitions, SchemaSchema } from './types/JSONSchema'\r\n-import { error, generateName, log } from './utils'\r\n+import { generateName, log } from './utils'\r\n+import stringify = require('json-stringify-safe')\r\n \r\n export type Processed = Map<JSONSchema | JSONSchema4Type, AST>\r\n \r\n@@ -142,7 +143,7 @@ function parseNonLiteral(\r\n         type: 'UNION'\r\n       })\r\n     case 'REFERENCE':\r\n-      throw error('Refs should have been resolved by the resolver!', schema)\r\n+      throw Error(`Refs should have been resolved by the resolver! ${stringify(schema, undefined, 2)}`)\r\n     case 'STRING':\r\n       return set({\r\n         comment: schema.description,\r\n@@ -261,7 +262,7 @@ function newNamedInterface(\r\n     return namedInterface\r\n   }\r\n   // TODO: Generate name if it doesn't have one\r\n-  throw error('Supertype must have standalone name!', namedInterface)\r\n+  throw Error(`Supertype must have standalone name! ${stringify(namedInterface,undefined,2)}`)\r\n }\r\n \r\n /**\r\n```\r\n\r\nThis results in the following output\r\n\r\n```json\r\nRefs should have been resolved by the resolver! {\r\n  \"definitions\": {\r\n    \"Something\": {\r\n      \"id\": \"Something\",\r\n      \"title\": \"The thing that is some\",\r\n      \"type\": \"object\",\r\n      \"required\": [\r\n        \"foo\",\r\n        \"bar\"\r\n      ],\r\n      \"additionalProperties\": false,\r\n      \"properties\": {\r\n        \"foo\": {\r\n          \"type\": \"string\",\r\n          \"title\": \"the value of bar\"\r\n        },\r\n        \"bar\": {\r\n          \"type\": \"string\",\r\n          \"title\": \"the value of foo\"\r\n        }\r\n      },\r\n      \"description\": \"\"\r\n    }\r\n  },\r\n  \"description\": \"\",\r\n  \"required\": [],\r\n  \"additionalProperties\": true,\r\n  \"id\": \"Broken\",\r\n  \"title\": \"The thing that is some\",\r\n  \"type\": \"object\",\r\n  \"properties\": {\r\n    \"foo\": {\r\n      \"type\": \"string\",\r\n      \"title\": \"the value of bar\"\r\n    },\r\n    \"bar\": {\r\n      \"type\": \"string\",\r\n      \"title\": \"the value of foo\"\r\n    }\r\n  },\r\n  \"$ref\": \"#\"\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/comments/422275787","html_url":"https://github.com/bcherny/json-schema-to-typescript/issues/182#issuecomment-422275787","issue_url":"https://api.github.com/repos/bcherny/json-schema-to-typescript/issues/182","id":422275787,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjI3NTc4Nw==","user":{"login":"bcherny","id":1761758,"node_id":"MDQ6VXNlcjE3NjE3NTg=","avatar_url":"https://avatars2.githubusercontent.com/u/1761758?v=4","gravatar_id":"","url":"https://api.github.com/users/bcherny","html_url":"https://github.com/bcherny","followers_url":"https://api.github.com/users/bcherny/followers","following_url":"https://api.github.com/users/bcherny/following{/other_user}","gists_url":"https://api.github.com/users/bcherny/gists{/gist_id}","starred_url":"https://api.github.com/users/bcherny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcherny/subscriptions","organizations_url":"https://api.github.com/users/bcherny/orgs","repos_url":"https://api.github.com/users/bcherny/repos","events_url":"https://api.github.com/users/bcherny/events{/privacy}","received_events_url":"https://api.github.com/users/bcherny/received_events","type":"User","site_admin":false},"created_at":"2018-09-18T06:50:44Z","updated_at":"2018-09-18T06:50:44Z","author_association":"OWNER","body":"359df5b6c5dbee8f8e74d71aa557e3b1acda8d0a"}}
{"actor":{"display_login":"bcherny"}}