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 {} does not show message #2755

Closed
andykais opened this issue May 26, 2021 · 4 comments
Closed

SqliteError {} does not show message #2755

andykais opened this issue May 26, 2021 · 4 comments
Labels
bug current functionality does not work as desired help wanted

Comments

@andykais
Copy link

Please provide details about:

  • What you're trying to do: run a test and view stack traces when things go wrong
  • What happened: I received an unexpected error, but the error message was not shown.
  • What you expected to happen: I expected to see the error message, which happens when most errors are thrown.

repro:
install the npm package better-sqlite3
run npx ava test.js with zero ava configuration

const test = require('ava')
const Sqlite3 = require('better-sqlite3')

test('sample', t => {
  const db = new Sqlite3('test.db')
  // this line will throw an exception
  db.prepare('invalid-syntax')

  t.pass()
})

this is the output:

 ✘ andrew  forager  npx ava test.js

  sample

  test.js:7

   6:   const db = new Sqlite3('test.db')
   7:   db.prepare('invalid-syntax')     
   8:                                    

  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

  ─

  1 test failed

contrast that with the following code sample:

const test = require('ava')

class CustomError extends Error {}

test('sample', t => {
  throw new CustomError('test message')
  t.pass()
})

we correctly see the error message:

  Error thrown in test:

  Error (CustomError) {
    message: 'test message',
  }

  › test.js:6:9

this is odd because if I catch the SqliteError, I can call error.message and see that there is a string there. I am unsure why it is not being displayed by ava.

ava version: 3.15.0

@andykais
Copy link
Author

I think I found the reason: https://github.com/JoshuaWise/better-sqlite3/blob/03f382a3ba1977feeb57ff1349c628b846d8b8b3/lib/sqlite-error.js#L2 (enumerable: false)

Is there a chance we can always look for a .message even on errors that are not enumerable?

@novemberborn
Copy link
Member

I agreed it'd be useful to print the message. I'm not immediately sure why it isn't being printed.

@novemberborn novemberborn added the bug current functionality does not work as desired label May 27, 2021
@novemberborn novemberborn added this to the 4.0 milestone May 27, 2021
@andykais
Copy link
Author

andykais commented May 27, 2021

@novemberborn its not printing the message because it makes the message property not enumerable for some reason https://github.com/JoshuaWise/better-sqlite3/blob/03f382a3ba1977feeb57ff1349c628b846d8b8b3/lib/sqlite-error.js#L13. A property that is not enumerable is one that you dont see doing something like Object.keys(sqliteError)

@novemberborn
Copy link
Member

@andykais gotcha. This isn't readily fixable in AVA, I've added concordancejs/concordance#77 on the dependency that formats the errors.

@novemberborn novemberborn removed this from the 4.0 milestone Sep 18, 2021
@novemberborn novemberborn closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired help wanted
Projects
None yet
Development

No branches or pull requests

2 participants