classifyErrorCode returns the most appropriate PostgreSQL SQLSTATE for a DuckDB error. Transaction conflicts get 40001 (serialization_failure), which signals PG-aware clients to retry. Query cancellations get 57014. Remaining errors are classified by DuckDB's exception-type prefix; the prefix is the
(err error)
| 67 | // a deadline. Distinct from a gRPC Canceled status that bubbles up purely |
| 68 | // because the CP closed the worker connection (worker death, takeover): in |
| 69 | // that case c.ctx is still healthy, c.ctx.Err() is nil, and the surface error |
| 70 | // must be logged as an infra failure rather than suppressed as "user |
| 71 | // cancelled". This matters for alerting — "Query execution errored." should |
| 72 | // fire on worker kills, not get silently downgraded to "Worker statement finished.". |
| 73 | func (c *clientConn) isCallerCancellation(err error) bool { |
| 74 | if c == nil { |
| 75 | return false |
| 76 | } |
| 77 | if c.statementTimedOut(err) { |
| 78 | return true |
| 79 | } |
| 80 | if !isQueryCancelled(err) { |
| 81 | return false |
| 82 | } |
| 83 | // A statement timeout is caller-driven even though the connection context is |
| 84 | // untouched, so it must not be logged as an infra failure. |
| 85 | if c.statementTimedOut(err) { |
| 86 | return true |
| 87 | } |
| 88 | if c.ctx == nil { |
| 89 | return false |
| 90 | } |
| 91 | return c.ctx.Err() != nil |
| 92 | } |
| 93 | |
| 94 | // isDuckLakeTransactionConflict returns true if the error is a DuckLake |
| 95 | // transaction conflict. These occur when concurrent DuckLake transactions |
| 96 | // try to commit overlapping changes. DuckLake uses global snapshot IDs, so |
| 97 | // even writes to unrelated tables can conflict under concurrency. |
| 98 | func isDuckLakeTransactionConflict(err error) bool { |
| 99 | if err == nil { |
| 100 | return false |
| 101 | } |
| 102 | msg := err.Error() |
| 103 | return strings.Contains(msg, "Transaction conflict") |
| 104 | } |
| 105 | |
| 106 | // isDuckLakeMetadataConnectionLost returns true if the error indicates the |
| 107 | // DuckLake metadata store connection was lost during a transaction. This |
| 108 | // typically happens when long-running queries leave the metadata connection |
| 109 | // idle long enough for RDS or a network layer to drop it. |
| 110 | func isDuckLakeMetadataConnectionLost(err error) bool { |
| 111 | if err == nil { |
| 112 | return false |
| 113 | } |
| 114 | msg := err.Error() |
| 115 | return strings.Contains(msg, "DuckLake transaction") && |
| 116 | strings.Contains(msg, "SSL connection has been closed unexpectedly") |
| 117 | } |
| 118 | |
| 119 | // classifyErrorCode returns the most appropriate PostgreSQL SQLSTATE for a |
| 120 | // DuckDB error. Transaction conflicts get 40001 (serialization_failure), which |
| 121 | // signals PG-aware clients to retry. Query cancellations get 57014. Remaining |