Skip to content

Commit 179f9dc

Browse files
authored
Merge pull request #197 from estie-inc/docs/error-handling-example-comments
docs(examples): focus error_handling doc comments on the error-reading pattern
2 parents 3c2b5c1 + 5702cb4 commit 179f9dc

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

examples/error_handling.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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
76
use 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.
7574
async 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.
10298
fn 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

Comments
 (0)