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

Unavoidable errors when DB response is null #6

Closed
ndianabasi opened this issue Feb 22, 2022 · 1 comment · Fixed by #7
Closed

Unavoidable errors when DB response is null #6

ndianabasi opened this issue Feb 22, 2022 · 1 comment · Fixed by #7

Comments

@ndianabasi
Copy link
Contributor

Prerequisites

I've noticed a persistent and unavoidable error when DB response is null. In a typical usage of the addon, not all attachment column will return the expected format which is parse-able by the add-on. Some columns will contain null values. The add-on current fails when null values are encountered.

The issue can be traced to these lines:

const attributes = typeof response === 'string' ? JSON.parse(response) : response
/**
* Validate the db response
*/
REQUIRED_ATTRIBUTES.forEach((attribute) => {
if (attributes[attribute] === undefined) {
throw new Exception(
`Cannot create attachment from database response. Missing attribute "${attribute}"`
)
}
})

When attributes is null, the Array.forEach call fails. A suggestion is for the add-on to provide a no-op when null is encountered.

Package version

1.0.1

Node.js and npm version

Node: 14.18.2. NPM: 6.14.15

Sample Code (to reproduce the issue)

const attributes = typeof response === 'string' ? JSON.parse(response) : response
/**
* Validate the db response
*/
REQUIRED_ATTRIBUTES.forEach((attribute) => {
if (attributes[attribute] === undefined) {
throw new Exception(
`Cannot create attachment from database response. Missing attribute "${attribute}"`
)
}
})

BONUS (a sample repo to reproduce the issue)

@thetutlage
Copy link
Member

Yeah we can ignore explicit null values to allow nullable columns

ndianabasi referenced this issue in ndianabasi/adonis-responsive-attachment Mar 2, 2022
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

Successfully merging a pull request may close this issue.

2 participants