1+ const NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX = '[NitroSQLiteException] ' as const
12const NITRO_SQLITE_ERROR_NAME = 'NitroSQLiteError' as const
2- const NITRO_SQLITE_ERROR_PREFIX = '[NitroSQLite] ' as const
3+ const getNitroSQLiteErrorPrefix = ( isNativeNitroSQLiteException : boolean ) =>
4+ isNativeNitroSQLiteException ? '[NitroSQLite (Native/C++)]' : '[NitroSQLite] '
5+
6+ type NitroSQLiteErrorOptions = ErrorOptions & {
7+ isNativeNitroSQLiteException ?: boolean
8+ }
39
410/**
511 * Custom error class for NitroSQLite operations
612 * Extends the native Error class with proper prototype chain and error handling
713 */
814export default class NitroSQLiteError extends Error {
9- constructor ( message : string , options ?: ErrorOptions ) {
10- super ( message , options )
15+ constructor ( message : string , options ?: NitroSQLiteErrorOptions ) {
16+ const { isNativeNitroSQLiteException = false , ...restOptions } =
17+ options ?? { }
18+
19+ super ( message , restOptions )
1120 this . name = NITRO_SQLITE_ERROR_NAME
12- this . message = NITRO_SQLITE_ERROR_PREFIX + message
21+ this . message =
22+ getNitroSQLiteErrorPrefix ( isNativeNitroSQLiteException ) + message
1323
1424 // Maintains proper prototype chain for instanceof checks
1525 Object . setPrototypeOf ( this , NitroSQLiteError . prototype )
@@ -25,6 +35,13 @@ export default class NitroSQLiteError extends Error {
2535 }
2636
2737 if ( error instanceof Error ) {
38+ if ( error . message . includes ( NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX ) ) {
39+ return new NitroSQLiteError ( error . message , {
40+ cause : error . cause ,
41+ isNativeNitroSQLiteException : true ,
42+ } )
43+ }
44+
2845 const nitroSQLiteError = new NitroSQLiteError ( error . message , {
2946 cause : error . cause ,
3047 } )
@@ -36,7 +53,11 @@ export default class NitroSQLiteError extends Error {
3653 }
3754
3855 if ( typeof error === 'string' ) {
39- return new NitroSQLiteError ( error )
56+ return new NitroSQLiteError ( error , {
57+ isNativeNitroSQLiteException : error . includes (
58+ NATIVE_NITRO_SQLITE_EXCEPTION_PREFIX ,
59+ ) ,
60+ } )
4061 }
4162
4263 return new NitroSQLiteError ( 'Unknown error occurred' , {
0 commit comments