gizdb:error
Typed failures shared by database owners; protocol spelling lives in sql/errors.giz.
import * as Error from "gizdb:error";Types
QueryErrorKind
type QueryErrorKind = | { kind: "invalid_role_grant"; } | { kind: "invalid_window"; } | { kind: "bad_copy"; } | { kind: "active_transaction"; } | { kind: "duplicate_routine"; } | { kind: "invalid_definition"; } | { kind: "stack_depth"; } | { kind: "missing_return"; } | { kind: "constant_assignment"; } | { kind: "case_missing"; } | { kind: "invalid_parameter"; } | { kind: "no_data"; } | { kind: "too_many_rows"; } | { kind: "transaction_termination"; } | { kind: "invalid_rethrow"; }Query-only causes keep their semantic identity without expanding the outer tag mask.
invalid_role_grantinvalid_windowbad_copyactive_transactionduplicate_routineinvalid_definitionstack_depthmissing_returnconstant_assignmentcase_missinginvalid_parameterno_datatoo_many_rowstransaction_terminationinvalid_rethrow
ErrorKind
type ErrorKind = | { kind: "state"; } | { kind: "aborted"; } | { kind: "blocked"; } | { kind: "check"; } | { kind: "conflict"; } | { kind: "corrupt"; } | { kind: "deadlock"; } | { kind: "dependent"; } | { kind: "exists"; } | { kind: "foreign"; } | { kind: "format"; } | { kind: "internal"; } | { kind: "invalid"; } | { kind: "io"; } | { kind: "limit"; } | { kind: "lock"; } | { kind: "memory"; } | { kind: "missing"; } | { kind: "missing_column"; } | { kind: "missing_portal"; } | { kind: "missing_routine"; } | { kind: "missing_statement"; } | { kind: "null"; } | { kind: "offset"; } | { kind: "protocol"; } | { kind: "schema"; } | { kind: "stopped"; } | { kind: "syntax"; } | { kind: "trimmed"; } | { kind: "type_mismatch"; } | { kind: "unique"; } | { kind: "unsupported"; } | { kind: "unavailable"; } | { kind: "division_zero"; } | { kind: "numeric_range"; } | { kind: "cardinality"; } | { kind: "invalid_text"; } | { kind: "string_length"; } | { kind: "datetime"; } | { kind: "date_day"; } | { kind: "date_month"; } | { kind: "foreign_referenced"; } | { kind: "sequence_not_allowed"; } | { kind: "sequence_missing"; } | { kind: "sequence_currval"; } | { kind: "sequence_bound"; } | { kind: "permission"; } | { kind: "missing_object"; } | { kind: "reserved_name"; } | { kind: "duplicate_object"; } | { kind: "query"; cause: QueryErrorKind; } | { kind: "external_io"; } | { kind: "program_limit"; } | { kind: "not_ready"; } | { kind: "cancelled"; } | { kind: "missing_file"; } | { kind: "null_value"; } | { kind: "invalid_offset"; } | { kind: "sqlstate"; state: string; } | { kind: "application"; number: i64; } | { kind: "exception"; name: string; } | { kind: "kafka"; number: i64; }The kind of a database error, from which its SQLSTATE and its class come.
stateabortedblockedcheckconflictcorruptdeadlockdependentexistsforeignformatinternalinvalidiolimitlockmemorymissingmissing_columnmissing_portalmissing_routinemissing_statementnulloffsetprotocolschemastoppedsyntaxtrimmedtype_mismatchuniqueunsupportedunavailabledivision_zeronumeric_rangecardinalityinvalid_textstring_lengthdatetimedate_daydate_monthforeign_referencedsequence_not_allowedsequence_missingsequence_currvalsequence_boundpermissionmissing_objectreserved_nameduplicate_objectqueryexternal_ioprogram_limitnot_readycancelledmissing_filenull_valueinvalid_offsetsqlstateapplicationexceptionkafka
FailureContext
type FailureContext = { stage: string; declaration: string; field: string; expected: string; actual: string; capability: string; permission: string; }Where an error happened: the stage, the declaration and field, and what was expected and found.
stage:stringdeclaration:stringfield:stringexpected:stringactual:stringcapability:stringpermission:string
DbError
type DbError = { code: ErrorKind; message: string; nativeCode: i64; context: Vec<FailureContext>; }A database error: its kind, message, the code of the native engine that raised it, and where it happened.
code:M56.ErrorKindmessage:stringnativeCode:i64context:Vec<M56.FailureContext>
Diagnostic
type Diagnostic = { error: DbError; stage: string; declaration: string; field: string; expected: string; actual: string; capabilities: Vec<string>; retry: string; permission: string; approval: bool; affected: Vec<string>; fixes: Vec<string>; }Context is attached at a boundary; semantic error classification stays here.
error:M56.DbErrorstage:stringdeclaration:stringfield:stringexpected:stringactual:stringcapabilities:Vec<string>retry:stringpermission:stringapproval:boolaffected:Vec<string>fixes:Vec<string>
ErrorInfo
type ErrorInfo = { kind: string; state: string; number: i64; name: string; }The class, SQLSTATE, number and name of an error, as each protocol reports it.
kind:stringstate:stringnumber:i64name:string
Functions
diagnostic
function diagnostic(error: DbError, stage: string, declaration: string): DiagnosticERROR as a diagnostic of STAGE and DECLARATION, with the context that it carries.
Effects: fail.
dbError
function dbError(code: ErrorKind, message: string): DbErrorAn error of the kind CODE with MESSAGE.
Effects: fail.
sqlFailure
function sqlFailure(code: string, message: string): Result<bool, DbError>The failed result of a statement with the SQLSTATE CODE.
Effects: fail.
contextual
function contextual(error: DbError, context: FailureContext): DbErrorERROR with CONTEXT added (at most 16).
Effects: fail.
withCleanup
function withCleanup(error: DbError, cleanup: string): DbErrorA failure whose cleanup also failed keeps its class and native cause; the message names both.
Effects: fail.
afterCleanup
function afterCleanup<T>(error: DbError, cleanup: Result<T, DbError>): DbErrorERROR after a cleanup that gave CLEANUP: the error, and the cleanup's failure in its message when it failed.
ioError
function ioError(error: IoError): DbErrorOne database boundary preserves resource refusal, stale ownership and I/O causes.
Effects: fail, io.
ioFailure
function ioFailure(action: string, error: IoError): DbErrorAn I/O failure of action ("open PATH"), with its native cause.
Effects: fail, io.
fromIo
function fromIo<T>(result: Result<T, IoError>): Result<T, DbError>RESULT with its system error as a database error.
errorInfo
function errorInfo(error: DbError): ErrorInfoExhaustive projection from typed causes; protocol text never decides a semantic failure.
semanticKind
function semanticKind(error: DbError): stringThe class of the error ("constraint", "missing", ...), as errorInfo gives it.
noRelation
function noRelation(name: string): DbError42P01: no relation NAME.
Effects: fail.
noColumn
function noColumn(column: string, relation: string): DbError42703: no column COLUMN in relation RELATION.
Effects: fail.
relationExists
function relationExists(name: string): DbError42P07: a relation NAME is there already.
Effects: fail.
fromMessage
function fromMessage<T>(result: Result<T, string>, code: ErrorKind): Result<T, DbError>RESULT with its text error as a database error of the kind CODE.
errorCode
function errorCode(error: DbError): stringDiagnostic spelling only; no decision reconstructs a kind from this text.
Effects: fail.
memoryError
function memoryError(message: string): DbErrorA statement whose working memory or result cannot fit its grant: out of memory (SQLSTATE 53200).
Effects: fail.
detailed
function detailed(code: ErrorKind, message: string, detail: string): DbErrorAn error with PostgreSQL's DETAIL line (the ErrorResponse D field; pg_input_error_info's detail).
Effects: fail.
errorDetail
function errorDetail(error: DbError): stringThe DETAIL line of an error, "" for none.
Effects: fail.
hinted
function hinted(error: DbError, hint: string): DbErrorAn error with PostgreSQL's HINT line (the ErrorResponse H field).
Effects: fail.
errorHint
function errorHint(error: DbError): stringThe HINT line of an error, "" for none.
Effects: fail.
positioned
function positioned(error: DbError, at: i64): DbErrorAn error at byte offset AT of the statement text (the ErrorResponse P field, from which psql draws its LINE).
Effects: fail.
errorPosition
function errorPosition(error: DbError): i64The byte offset an error names in the statement text, -1 for none.
Effects: fail.