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

Error when data value is undefined #154

Open
ZeRego opened this issue Sep 6, 2022 · 0 comments
Open

Error when data value is undefined #154

ZeRego opened this issue Sep 6, 2022 · 0 comments

Comments

@ZeRego
Copy link

ZeRego commented Sep 6, 2022

Our code:

betterAjvErrors(
    lightdashDbtYamlSchema,
    schemaFile,
    validate.errors || [],
    { indent: 2 },
);

Values:

schemaFile is undefined

validate.errors is

[
  {
    instancePath: '',
    schemaPath: '#/type',
    keyword: 'type',
    params: { type: 'object' },
    message: 'must be object'
  }
]

Error:

e TypeError: Cannot read properties of undefined (reading 'charAt')
    at next (/Users/joserego/Documents/lightdash/node_modules/@humanwhocodes/momoa/api.js:235:22)
    at tokenize (/Users/joserego/Documents/lightdash/node_modules/@humanwhocodes/momoa/api.js:491:13)
    at parse (/Users/joserego/Documents/lightdash/node_modules/@humanwhocodes/momoa/api.js:726:20)
    at Object.src_default (/Users/joserego/Documents/lightdash/packages/cli/node_modules/better-ajv-errors/lib/cjs/index.js:31:42)
    at /Users/joserego/Documents/lightdash/packages/cli/dist/dbt/schema.js:55:49
    at Generator.next (<anonymous>)
    at fulfilled (/Users/joserego/Documents/lightdash/packages/cli/dist/dbt/schema.js:24:58)

Workaround

By making sure the data defaults to an empty string or an empty object or null.

betterAjvErrors(
    lightdashDbtYamlSchema,
    schemaFile || '',
    validate.errors || [],
    { indent: 2 },
);

And with this get the proper error:

TYPE must be object

> 1 | ""
    | ^^ 👈🏽  type must be object

Solution:

better-ajv-errors could make sure data can't be undefined.
Or support undefined and have an appropriate message.

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