Repository navigation
fix(sea): propagate status-level SQLSTATE #259
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
Changes from all commits
e98d68d
52809c6
0427398
dad9961
f83fd67
b2cd3f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -680,6 +680,29 @@ pub(crate) fn carry_extended_status( | |
|
|
||
| // ─── SQLSTATE extraction helpers ──────────────────────────────────── | ||
|
|
||
| /// Extract the SQLSTATE from a SEA statement status. | ||
| /// | ||
| /// Prefer the canonical `status.sql_state`, then parse | ||
| /// `status.error.message`. The nested `status.error.sql_state` field | ||
| /// belongs to the shared transport-error shape and is intentionally | ||
| /// ignored for statement failures. | ||
| pub(crate) fn extract_sqlstate_from_status( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — This is deliberate and documented, and the message-parsing fallback plus the message-substring branch in If you've confirmed no live/older server populates only the nested field for statement failures, this is fine as-is — worth a one-line note in the PR that the drop was validated against those responses, since the moved wiremock fixtures previously exercised the nested placement.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sql state should be derived from statementstatus directly, not sure why we use status.error.sql_state previously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That design principle is reasonable — deriving SQLSTATE from
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is fine, we should use status.sql_state as the source of truth for SEA path There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The design direction here is sound — treating |
||
| status: &crate::types::sea::StatementStatus, | ||
| ) -> Option<String> { | ||
| status | ||
| .sql_state | ||
| .as_ref() | ||
| .filter(|s| s.len() == 5) | ||
| .cloned() | ||
| .or_else(|| { | ||
| status | ||
| .error | ||
| .as_ref() | ||
| .and_then(|error| error.message.as_deref()) | ||
| .and_then(extract_sqlstate_from_message) | ||
| }) | ||
| } | ||
|
|
||
| /// Extract a SQLSTATE from a free-form error message. | ||
| /// | ||
| /// Many Databricks error envelopes include `SQLSTATE: XXXXX` in the | ||
|
|
@@ -828,6 +851,64 @@ mod tests { | |
| assert_eq!(extract_sqlstate_from_message("nope"), None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn extract_sqlstate_from_status_prefers_top_level_field() { | ||
| let status: crate::types::sea::StatementStatus = serde_json::from_str( | ||
| r#"{ | ||
| "state": "FAILED", | ||
| "sql_state": "57KD0", | ||
| "error": { | ||
| "message": "legacy SQLSTATE: 42000" | ||
| } | ||
| }"#, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| extract_sqlstate_from_status(&status).as_deref(), | ||
| Some("57KD0") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn extract_sqlstate_from_status_falls_back_to_error_message() { | ||
| let status: crate::types::sea::StatementStatus = serde_json::from_str( | ||
| r#"{ | ||
| "state": "FAILED", | ||
| "error": { | ||
| "message": "table not found. SQLSTATE: 42P01" | ||
| } | ||
| }"#, | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| extract_sqlstate_from_status(&status).as_deref(), | ||
| Some("42P01") | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn extract_sqlstate_from_status_ignores_nested_field() { | ||
| use crate::types::sea::{ServiceError, StatementState, StatementStatus}; | ||
|
|
||
| let status = StatementStatus { | ||
| state: StatementState::Failed, | ||
| error: Some(ServiceError { | ||
| error_code: None, | ||
| message: Some("table not found".to_string()), | ||
| sql_state: Some("42P01".to_string()), | ||
| }), | ||
| sql_state: None, | ||
| num_modified_rows: None, | ||
| display_message: None, | ||
| diagnostic_info: None, | ||
| error_details_json: None, | ||
| }; | ||
|
|
||
| assert_eq!(extract_sqlstate_from_status(&status), None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn display_includes_code_message_and_sqlstate() { | ||
| let e = Error::sql_error() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.