search for standard sites pub-search.waow.tech
search zig blog atproto
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: improve db error logging with context

- include error name, SQL, and response preview in error logs
- local db errors now show: error name + sql
- turso errors now show: status + sql + response body preview

makes debugging db errors much easier

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

zzstoatzz 4d8bae1b 4443f90e

+13 -7
+10 -4
backend/src/db/Client.zig
··· 150 150 .payload = body, 151 151 .response_writer = &response_body.writer, 152 152 }) catch |err| { 153 - logfire.err("turso request failed: {}", .{err}); 153 + logfire.err("db.query http failed: {s} | sql: {s}", .{ @errorName(err), truncateSql(sql) }); 154 154 return error.HttpError; 155 155 }; 156 156 157 157 if (res.status != .ok) { 158 - logfire.err("turso error: {}", .{res.status}); 158 + const resp_text = response_body.toOwnedSlice() catch ""; 159 + defer if (resp_text.len > 0) self.allocator.free(resp_text); 160 + const resp_preview = if (resp_text.len > 200) resp_text[0..200] else resp_text; 161 + logfire.err("db.query turso error: {} | sql: {s} | response: {s}", .{ res.status, truncateSql(sql), resp_preview }); 159 162 return error.TursoError; 160 163 } 161 164 ··· 197 200 .payload = body, 198 201 .response_writer = &response_body.writer, 199 202 }) catch |err| { 200 - logfire.err("turso batch request failed: {}", .{err}); 203 + logfire.err("db.batch http failed: {s} | first_sql: {s}", .{ @errorName(err), first_sql }); 201 204 return error.HttpError; 202 205 }; 203 206 204 207 if (res.status != .ok) { 205 - logfire.err("turso batch error: {}", .{res.status}); 208 + const resp_text = response_body.toOwnedSlice() catch ""; 209 + defer if (resp_text.len > 0) self.allocator.free(resp_text); 210 + const resp_preview = if (resp_text.len > 200) resp_text[0..200] else resp_text; 211 + logfire.err("db.batch turso error: {} | first_sql: {s} | response: {s}", .{ res.status, first_sql, resp_preview }); 206 212 return error.TursoError; 207 213 } 208 214
+3 -3
backend/src/db/LocalDb.zig
··· 267 267 268 268 const c = self.conn orelse return error.NotOpen; 269 269 const rows = c.rows(sql, args) catch |e| { 270 - logfire.err("local db query error: {}", .{e}); 270 + logfire.err("db.local.query failed: {s} | sql: {s}", .{ @errorName(e), truncateSql(sql) }); 271 271 return e; 272 272 }; 273 273 return .{ .inner = rows }; ··· 285 285 286 286 const c = self.conn orelse return error.NotOpen; 287 287 const row = c.row(sql, args) catch |e| { 288 - logfire.err("local db queryOne error: {}", .{e}); 288 + logfire.err("db.local.queryOne failed: {s} | sql: {s}", .{ @errorName(e), truncateSql(sql) }); 289 289 return e; 290 290 }; 291 291 if (row) |r| { ··· 301 301 302 302 const c = self.conn orelse return error.NotOpen; 303 303 c.exec(sql, args) catch |e| { 304 - std.debug.print("local db exec error: {}\n", .{e}); 304 + logfire.err("db.local.exec failed: {s} | sql: {s}", .{ @errorName(e), truncateSql(sql) }); 305 305 return e; 306 306 }; 307 307 }