flanksource / duty

Apache License 2.0
1 stars 1 forks source link

feat: add pg error details capture #865

Closed yashmehrotra closed 6 days ago

yashmehrotra commented 6 days ago

Previous:

2024-06-25T18:59:57.372 ERROR   ERROR: update or delete on table "config_items" violates foreign key constraint 
"config_items_parent_id_fkey" on table "config_items" (SQLSTATE 23503)

New:

2024-06-25T18:59:57.372 ERROR   ERROR: update or delete on table "config_items" violates foreign key constraint 
"config_items_parent_id_fkey" on table "config_items" (SQLSTATE 23503): detail: Key (id)=(f5c71026-fcab-4709-
ae00-2edcc7e3086a) is still referenced from table "config_items".

Usage:

if err := dutyCtx.DB().Exec(query).Error; err != nil {
    err = duty.DBErrorDetails(err)
    ...
}

// or

if err := duty.DBErrorDetails(dutyCtx.DB().Exec(query).Error);  err != nil {
    ...
}