Documentation
¶
Overview ¶
Package dberr words a database statement's error without the values a driver's message may quote. db's statement log and telemetry's span status both say a failed statement's error with Text, so the log and the trace name the same driver, code and names, and neither carries a bound value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Text ¶
Text is what the log and the trace say of a statement's error: db's statement log writes it beside the statement, telemetry sets it as the status of the statement's span. The drivers' messages quote the values a statement bound: MySQL's Duplicate entry 'x' for key 'k', Incorrect integer value 'x' for column 'c' and Truncated incorrect DOUBLE value 'x', Postgres's invalid input syntax for type integer "x" and value "x" is out of range. The SQL beside the error keeps placeholders, and the message would bring back the values it leaves out. So a Postgres or MySQL error is written as its driver, its code and the names it carries: Postgres's constraint, table and column fields, the key a MySQL duplicate names. With the statement, they locate the fault:
postgres 23505 constraint uk_user_email table users mysql 1062 (23000) key users.uk_user_email mysql 1366 (HY000)
SQLite's messages name objects (UNIQUE constraint failed: users.email) and are kept, except two kinds written as their code alone (sqlite 1, sqlite 1811). SQLITE_ERROR is the code of SQL that does not compile, whose message quotes the SQL, and of a value a function or a virtual table refuses, whose message may quote it: a JSON path, a word of an FTS5 query. A trigger's RAISE text is the trigger's and may quote the row. database/sql's own error for a value it cannot scan into the destination quotes the value as well; it is cut out and the rest of the message kept. pgx's error for an argument it cannot encode for the type of its parameter, which a raw statement given a Go value of the wrong type meets, quotes the argument: it is cut after the argument's index (failed to encode args[0]), or, where pgx's simple protocol returns pgtype's error bare, after the type it encoded for (unable to encode into text format for unknown type (OID 0)). A Postgres or MySQL error that lost its type is written as its driver and code, and the text around it is kept: gorm keeps the type of a statement's last error alone, so when the rollback fails after the statement, the statement's error is text before the rollback's (mysql 1062 (23000); driver: bad connection). Any other error, a network fault, a cancellation, gorm's or chok's own, is kept as it is. The caller gets the error unchanged, and db's expected reads its type and code.
Types ¶
This section is empty.