Skip to content

Commit

Permalink
qe: Fix JS errors propogation for raw queries (#4195)
Browse files Browse the repository at this point in the history
There is one more error type, specific to previous queries that previous
PR missed.
  • Loading branch information
SevInf authored Sep 4, 2023
1 parent b52b336 commit d9219f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions query-engine/connectors/sql-query-connector/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub(crate) enum RawError {
UnsupportedColumnType {
column_type: String,
},
External {
id: i32,
},
}

impl From<RawError> for SqlError {
Expand All @@ -39,6 +42,7 @@ impl From<RawError> for SqlError {
code: code.unwrap_or_else(|| String::from("N/A")),
message: message.unwrap_or_else(|| String::from("N/A")),
},
RawError::External { id } => Self::ExternalError(id),
}
}
}
Expand All @@ -57,6 +61,7 @@ impl From<quaint::error::Error> for RawError {
column_type: column_type.to_owned(),
},
quaint::error::ErrorKind::QueryInvalidInput(message) => Self::QueryInvalidInput(message.to_owned()),
quaint::error::ErrorKind::ExternalError(id) => Self::External { id: *id },
_ => Self::Database {
code: e.original_code().map(ToString::to_string),
message: e.original_message().map(ToString::to_string),
Expand Down
20 changes: 20 additions & 0 deletions query-engine/js-connectors/js/smoke-test-js/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function smokeTest(db: ErrorCapturingConnector, prismaSchemaRelativ
await test.createAutoIncrement()
await test.testCreateAndDeleteChildParent()
await test.testTransaction()
await test.testRawError()

// Note: calling `engine.disconnect` won't actually close the database connection.
console.log('[nodejs] disconnecting...')
Expand Down Expand Up @@ -420,6 +421,25 @@ class SmokeTest {
console.log('[nodejs] commited', commitResponse)
}

async testRawError() {
try {
await this.doQuery({
action: 'queryRaw',
query: {
selection: { $scalars: true },
arguments: {
query: 'NOT A VALID SQL, THIS WILL FAIL',
parameters: '[]'
}
}
})
console.log(`[nodejs] expected exception, but query succeeded`)
} catch (error) {
console.log('[nodejs] caught expected error', error)
}

}

private async doQuery(query: JsonQuery, tx_id?: string) {
const result = await this.engine.query(JSON.stringify(query), 'trace', tx_id)
const parsedResult = JSON.parse(result)
Expand Down

0 comments on commit d9219f6

Please sign in to comment.