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

SqliteError message is not enumerable, test frameworks tend to ignore it #633

Closed
andykais opened this issue May 29, 2021 · 2 comments
Closed

Comments

@andykais
Copy link

I created an issue in the ava test repo (avajs/ava#2755) that explains how sqlite error messages are not shown. It looks like the cause of it is that the errors are not enumerable (see here https://github.com/JoshuaWise/better-sqlite3/blob/master/lib/sqlite-error.js#L13)

Errors end up looking like this:

  Error thrown in test:

  SqliteError {}

  › Database.prepare (node_modules/.pnpm/[email protected]/node_modules/better-sqlite3/lib/methods/wrappers.js:5:21)
  › test.js:7:6

Is there a reason error messages need to be not enumerable?

@Prinzhorn
Copy link
Contributor

I don't think enumerability per se is the problem, see also #575 (comment)

(new Error('test')).propertyIsEnumerable('message')
false
(new (class CustomError extends Error{})('test')).propertyIsEnumerable('message')
false

How does ava serialize the Error for printing? It looks like neither toString nor util.inspect

@JoshuaWise
Copy link
Member

I've changed the code property to be enumerable, as of better-sqlite3 version 7.5.0.

Originally, I made it non-enumerable to match the message property that every error has. However, after reflecting on the Node.js and JavaScript ecosystem, I realized that custom properties of error objects are pretty much always enumerable, to aid in discoverability (i.e., so they appear when using console.log).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants