MCPcopy Create free account
hub / github.com/erans/pgsqlite / to_error_response

Method to_error_response

src/error.rs:44–186  ·  view source on GitHub ↗

Convert to ErrorResponse for protocol

(&self)

Source from the content-addressed store, hash-verified

42impl PgError {
43 /// Convert to ErrorResponse for protocol
44 pub fn to_error_response(&self) -> ErrorResponse {
45 match self {
46 PgError::StringDataRightTruncation { type_name, column_name, actual_length, max_length } => {
47 ErrorResponse {
48 severity: "ERROR".to_string(),
49 code: "22001".to_string(),
50 message: format!("value too long for type {type_name}"),
51 detail: Some(format!(
52 "Failing row contains ({column_name}) with {actual_length} characters, maximum is {max_length}."
53 )),
54 hint: None,
55 position: None,
56 internal_position: None,
57 internal_query: None,
58 where_: None,
59 schema: None,
60 table: None,
61 column: Some(column_name.clone()),
62 datatype: Some(type_name.clone()),
63 constraint: None,
64 file: None,
65 line: None,
66 routine: None,
67 }
68 }
69 PgError::NumericValueOutOfRange { type_name, column_name, value: _ } => {
70 ErrorResponse {
71 severity: "ERROR".to_string(),
72 code: "22003".to_string(),
73 message: "numeric field overflow".to_string(),
74 detail: Some({
75 // Parse numeric(p,s) to extract precision and scale
76 let params = type_name.split('(').nth(1).unwrap_or("").trim_end_matches(')');
77 let parts: Vec<&str> = params.split(',').collect();
78 let precision = parts.first().unwrap_or(&"").trim();
79 let scale = parts.get(1).unwrap_or(&"0").trim();
80 format!(
81 "A field with precision {}, scale {} must round to an absolute value less than 10^({}-{}) = 10^{}.",
82 precision, scale, precision, scale,
83 precision.parse::<i32>().unwrap_or(0) - scale.parse::<i32>().unwrap_or(0)
84 )
85 }),
86 hint: None,
87 position: None,
88 internal_position: None,
89 internal_query: None,
90 where_: None,
91 schema: None,
92 table: None,
93 column: Some(column_name.clone()),
94 datatype: Some(type_name.clone()),
95 constraint: None,
96 file: None,
97 line: None,
98 routine: None,
99 }
100 }
101 PgError::UniqueViolation { constraint_name, detail } => {

Callers 2

execute_dmlMethod · 0.80
handle_executeMethod · 0.80

Calls 2

cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected