MCPcopy Create free account
hub / github.com/PostHog/duckgres / isUserQueryError

Function isUserQueryError

server/conn_errors.go:278–288  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
281func 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

Callers 2

logQueryErrorMethod · 0.85
TestIsUserQueryErrorFunction · 0.85

Calls 1

classifyErrorCodeFunction · 0.85

Tested by 1

TestIsUserQueryErrorFunction · 0.68