diff --git a/snowflake-api/examples/tracing/src/main.rs b/snowflake-api/examples/tracing/src/main.rs index 2c1c002..dd8e834 100644 --- a/snowflake-api/examples/tracing/src/main.rs +++ b/snowflake-api/examples/tracing/src/main.rs @@ -57,7 +57,7 @@ async fn run_in_span(api: &snowflake_api::SnowflakeApi) -> anyhow::Result<()> { match res { QueryResult::Arrow(a) => { - println!("{}", pretty_format_batches(&a).unwrap()); + println!("{}", pretty_format_batches(&a[..]).unwrap()); } QueryResult::Json(j) => { println!("{}", j); diff --git a/snowflake-api/src/responses.rs b/snowflake-api/src/responses.rs index 9a687fa..52eaeae 100644 --- a/snowflake-api/src/responses.rs +++ b/snowflake-api/src/responses.rs @@ -11,7 +11,6 @@ pub enum ExecResponse { Error(ExecErrorResponse), } -// todo: add close session response, which should be just empty? #[allow(clippy::large_enum_variant)] #[derive(Deserialize, Debug)] #[serde(untagged)] @@ -21,6 +20,8 @@ pub enum AuthResponse { Renew(RenewSessionResponse), Close(CloseSessionResponse), Error(AuthErrorResponse), + ExecError(ExecErrorResponse), + Other(serde_json::Value), } #[derive(Deserialize, Debug)] @@ -53,9 +54,8 @@ pub struct ExecErrorResponseData { pub line: Option, pub pos: Option, - // fixme: only valid for exec query response error? present in any exec query response? - pub query_id: String, - pub sql_state: String, + pub query_id: Option, + pub sql_state: Option, } #[derive(Deserialize, Debug)] diff --git a/snowflake-api/src/session.rs b/snowflake-api/src/session.rs index 90acaaf..48a6960 100644 --- a/snowflake-api/src/session.rs +++ b/snowflake-api/src/session.rs @@ -35,7 +35,7 @@ pub enum AuthError { MissingCertificate, #[error("Unexpected API response")] - UnexpectedResponse, + UnexpectedResponse(Option), // todo: add code mapping to meaningful message and/or refer to docs // eg https://docs.snowflake.com/en/user-guide/key-pair-auth-troubleshooting @@ -269,7 +269,12 @@ impl Session { e.code.unwrap_or_default(), e.message.unwrap_or_default(), )), - _ => Err(AuthError::UnexpectedResponse), + AuthResponse::ExecError(e) => Err(AuthError::AuthFailed( + e.code.unwrap_or_default(), + e.message.unwrap_or_default(), + )), + AuthResponse::Other(value) => Err(AuthError::UnexpectedResponse(Some(value))), + _ => Err(AuthError::UnexpectedResponse(None)), } } else { Ok(()) @@ -356,7 +361,12 @@ impl Session { e.code.unwrap_or_default(), e.message.unwrap_or_default(), )), - _ => Err(AuthError::UnexpectedResponse), + AuthResponse::ExecError(e) => Err(AuthError::AuthFailed( + e.code.unwrap_or_default(), + e.message.unwrap_or_default(), + )), + AuthResponse::Other(value) => Err(AuthError::UnexpectedResponse(Some(value))), + _ => Err(AuthError::UnexpectedResponse(None)), } } @@ -416,7 +426,12 @@ impl Session { e.code.unwrap_or_default(), e.message.unwrap_or_default(), )), - _ => Err(AuthError::UnexpectedResponse), + AuthResponse::ExecError(e) => Err(AuthError::AuthFailed( + e.code.unwrap_or_default(), + e.message.unwrap_or_default(), + )), + AuthResponse::Other(value) => Err(AuthError::UnexpectedResponse(Some(value))), + _ => Err(AuthError::UnexpectedResponse(None)), } } }