surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
272 stars 45 forks source link

Bug Errors are mostly unusable: #207

Open jquesada2016 opened 6 months ago

jquesada2016 commented 6 months ago

Describe the bug

Errors that are thrown from the JS SDK are mostly unusable, because almost all of them are plain new Error(/* ... */) invocations, rather than proper classified errors, like those provided in errors.ts. This leaves users using generic try/catch along with string literal matching in the .message field in order to try and detect what type of error is thrown. This is problematic, because it would likely not be a breaking change if the underlying Rust error string representation changed, which would break users relying on message content when discerning errors.

All possible errors can be found here.

Steps to reproduce

try {
  await db.query(`
  throw "I am an error";

  as kjdf kj f // <-- syntax error
  `)
} catch(err) {
  // What is it??? syntax error or thrown error???}
}

Expected behaviour

Provide some way of discerning between error kinds.

SurrealDB version

1.1.0

SurrealDB.js version

0.11.0

Contact Details

No response

Is there an existing issue for this?

Code of Conduct

mirsella commented 5 months ago

The same is true for scope signup / signin clause too, ex having custom logic in theses expression with throw will always result in the same error without the throwed message