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

Null type in mysql throws error. Possible solution. #47

Open
RobAley opened this issue Jan 29, 2019 · 1 comment
Open

Null type in mysql throws error. Possible solution. #47

RobAley opened this issue Jan 29, 2019 · 1 comment

Comments

@RobAley
Copy link

RobAley commented Jan 29, 2019

The following json (partial from the github api) :

{
  "message": "Out-of-srcdir builds: AM_CPPFLAGS=-I${srcdir}/src",
  "tree": {
    "sha": "5b9f0e1342264d1465fa7001faec3902c89ca944",
    "url": "https://api.github.com/repos/stedolan/jq/git/trees/5b9f0e1342264d1465fa7001faec3902c89ca944"
  },
  "url": "https://api.github.com/repos/stedolan/jq/git/commits/0bc77083ba711e1961db1cb2ebc9de7c71d1a746",
  "comment_count": 0,
  "verification": {
    "verified": false,
    "reason": "unsigned",
    "signature": null,
    "payload": null
  }
}

throws the following error when converting to mysql :

src/utils.js:12 Uncaught (in promise) TypeError: Cannot read property 'length' of null
    at Object.exports.isTimestamp (src/utils.js:12)
    at processObject (schemas/mysql.js:93)
    at processObject (schemas/mysql.js:103)
    at processObject (schemas/mysql.js:103)
    at processObject (schemas/mysql.js:103)
    at Object.Process [as mysql] (schemas/mysql.js:162)

as Utils.isTimestamp() doesn't like nulls instead of strings. Changing line 92 of mysql.js from :

       if (type !== 'undefined') {

to

if (type !== 'undefined' && type !== 'null') {

seems to fix this, and the type for null fields like this (signature and payload in the example json above) becomes string, which in my case is the correct handling.

I haven't submitted a pull request as I'm not sure that this is the correct handling in all cases / the generic case, and I don't know enough about the code to know if it will cause any other unintended side effects.

Thanks for a great library.

@RobAley
Copy link
Author

RobAley commented Jan 29, 2019

Just to add that I noticed when playing around this json also throws a similar error in bigquery(), but I know nothing of / don't use bigquery so I can't speculate whether a fix is needed there :

generate-schema/src/schemas/bigquery.js:28 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at processFields (generate-schema/src/schemas/bigquery.js:28)
    at generate-schema/src/schemas/bigquery.js:37
    at Array.map (<anonymous>)
    at processFields (generate-schema/src/schemas/bigquery.js:28)
    at generate-schema/src/schemas/bigquery.js:37
    at Array.map (<anonymous>)
    at processFields generate-schema/src/schemas/bigquery.js:28)
    at generate-schema/src/schemas/bigquery.js:37
    at Array.map (<anonymous>)

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