isUserQueryError tells the log/observability path whether a query failure is user-attributable (Info-level "Query execution failed.") or a real system error worth alerting on (Error-level "Query execution errored."). The discriminator is the SQLSTATE class — already computed via classifyErrorCode fo
(err error)
| 276 | } |
| 277 | |
| 278 | // constraintErrorCode narrows a "Constraint Error: …" message to one of the |
| 279 | // integrity_constraint_violation family codes. DuckDB's messages name the |
| 280 | // violated constraint explicitly, so substring matching is reliable. |
| 281 | func constraintErrorCode(msg string) string { |
| 282 | lower := strings.ToLower(msg) |
| 283 | switch { |
| 284 | case strings.Contains(lower, "duplicate key") || strings.Contains(lower, "unique"): |
| 285 | return "23505" // unique_violation |
| 286 | case strings.Contains(lower, "not null") || strings.Contains(lower, "null value"): |
| 287 | return "23502" // not_null_violation |
| 288 | case strings.Contains(lower, "foreign key"): |
| 289 | return "23503" // foreign_key_violation |
| 290 | case strings.Contains(lower, "check constraint"): |
| 291 | return "23514" // check_violation |