1- //! Inspecting [`snowflake_connector_rs::Error`] without a live Snowflake account.
1+ //! The recommended way to handle [`snowflake_connector_rs::Error`]: branch on `kind()`, then read the structured fields
2+ //! through the accessors.
23//!
3- //! A minimal mock server stands in for Snowflake: it accepts the login request, then answers the statement request with a
4- //! canned failure. Each scenario drives the public client API to produce a real `Error`, and `describe` shows the recommended
5- //! way to read it — branch on `kind()`, then use the accessors.
4+ //! Each scenario produces a real `Error` through the public client API, and `describe` shows the extraction pattern.
65
76use std:: {
87 io:: { Read , Write } ,
@@ -71,7 +70,7 @@ fn describe(err: &Error) {
7170 println ! ( "display = {err}" ) ;
7271}
7372
74- /// Point a client at the mock server, run a query , and return the resulting error.
73+ /// Run a query against a server that fails it with `query_response` , and return the resulting error.
7574async fn provoke_error ( query_response : & ' static str ) -> Error {
7675 let base_url = spawn_mock_snowflake ( vec ! [ LOGIN_OK , query_response] ) ;
7776
@@ -96,17 +95,13 @@ async fn provoke_error(query_response: &'static str) -> Error {
9695 }
9796}
9897
99- /// Serve `responses` in order, one per incoming connection, then stop.
100- ///
101- /// This is deliberately just enough HTTP to satisfy the connector; a real test harness would use a proper mock-server crate.
10298fn spawn_mock_snowflake ( responses : Vec < & ' static str > ) -> String {
10399 let listener = TcpListener :: bind ( ( "127.0.0.1" , 0 ) ) . expect ( "bind mock server" ) ;
104100 let addr = listener. local_addr ( ) . expect ( "mock server address" ) ;
105101
106102 thread:: spawn ( move || {
107103 for body in responses {
108104 let ( mut stream, _) = listener. accept ( ) . expect ( "accept connection" ) ;
109- // Read the request so the client can finish sending before we reply.
110105 let mut buf = [ 0_u8 ; 8192 ] ;
111106 let _ = stream. read ( & mut buf) ;
112107
0 commit comments