atlassian / atlassian/better-ajv-errors
Error when data value is undefined
- Dominant language
- JavaScript
- Stars
- 245
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
### 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 ()
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the better-ajv-errors API that receives the undefined data value and reproduce the call shown in the issue. Trace how that value reaches parsing, then determine whether completion should reject undefined clearly or support it with an appropriate validation message; the existing empty-string workaround provides the expected failure context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100