{"record":{"id":"4e3af424882856ba","repo":"gastownhall/beads","slug":"db-rawsql-exec-w","errorCode":null,"errorMessage":"db: RawSQL Exec: %w","messagePattern":"db: RawSQL Exec: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/raw_sql.go","lineNumber":58,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"db: RawSQL Query: scan: %w\", err)\n\t\t}\n\t\tfor i, v := range values {\n\t\t\tif b, ok := v.([]byte); ok {\n\t\t\t\tvalues[i] = string(b)\n\t\t\t}\n\t\t}\n\t\tresult.Rows = append(result.Rows, values)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"db: RawSQL Query: rows: %w\", err)\n\t}\n\treturn result, nil\n}\n\nfunc (r *rawSQLRepositoryImpl) Exec(ctx context.Context, query string, args ...any) (int64, error) {\n\tres, err := r.runner.ExecContext(ctx, query, args...)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"db: RawSQL Exec: %w\", err)\n\t}\n\taffected, err := res.RowsAffected()\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"db: RawSQL Exec: rows affected: %w\", err)\n\t}\n\treturn affected, nil\n}\n","sourceCodeStart":40,"sourceCodeEnd":66,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/raw_sql.go#L40-L66","documentation":"Wraps an error from ExecContext in RawSQLRepository.Exec. Exec runs a statement that returns no rows; the driver rejected or failed to execute it. This is the standard failure point for malformed SQL, constraint violations, lock contention, or connectivity problems.","triggerScenarios":"Calling RawSQLRepository.Exec with invalid SQL syntax, unknown table/column, constraint violation (dup key, FK), lock-wait timeout, or a dead connection.","commonSituations":"Hand-written migration/DML statements with typos; writing to a table that does not exist in the current schema version; deadlocks or lock waits under concurrency; referencing wisps tables that are absent in durable-only setups.","solutions":["Read the wrapped driver error — it names the exact SQL problem (syntax, missing table, constraint)","Verify the statement against the current schema (tables/columns exist)","Retry on lock-wait/deadlock errors; check for contending transactions","If targeting wisp tables, ensure they exist in this deployment mode or route to the right table"],"exampleFix":"// before\nn, err := repo.Exec(ctx, \"DELET FROM issues WHERE id = ?\", id) // syntax error\n// after\nn, err := repo.Exec(ctx, \"DELETE FROM issues WHERE id = ?\", id)","handlingStrategy":"validation","validationCode":"// validate the statement against the schema before exec\nvar cnt int\n_ = db.QueryRow(\"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?\", \"issues\").Scan(&cnt)\n// cnt == 0 => table missing; abort before Exec","typeGuard":"func isExecError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"db: RawSQL Exec:\") && !strings.Contains(err.Error(), \"rows affected\")\n}","tryCatchPattern":"n, err := repo.Exec(ctx, stmt, args...)\nif err != nil {\n\tvar mysqlErr *mysqldriver.MySQLError\n\tif errors.As(err, &mysqlErr) && (mysqlErr.Number == 1213 || mysqlErr.Number == 1205) {\n\t\t// deadlock/lock-wait: retry\n\t}\n\treturn err\n}","preventionTips":["Test raw statements against a schema-matched staging DB","Handle deadlocks/lock waits with bounded retries","Ensure target tables exist for the current deployment mode","Use parameterized arguments, never string interpolation"],"tags":["database","sql","exec","raw-sql"],"backgroundTag":"sql-exec-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}