SShortSingh.
Back to feed

Go error wrapping, unwrapping, and sentinel errors for production code

0
·3 views

Go's error handling is often criticized, but the real difficulty lies in the patterns built around bare error returns, which yield logs lacking location or context. The article shows how fmt.Errorf with the %w verb, introduced in Go 1.13, attaches caller context while preserving the original error for inspection. It recommends wrapping at the point of origin rather than repeatedly across layers, since redundant wrapping only adds noise. Sentinel errors let callers branch on meaningful categories such as not-found, and errors.Is traverses the wrapped chain to detect them. Custom error types are suggested for carrying structured data like validation fields or status codes.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Closing a Terminal Sends Coding Agents SIGHUP; Session Hosts Can Keep Them Running

Closing a terminal window can kill a coding agent that is running in it, because the kernel signals the shell that the terminal has hung up. The shell then forwards that signal to its background jobs, so unsaved work in the agent process is lost. Common workarounds such as nohup, disown, setsid, and tmux each address a different part of this chain. Only some of them leave the agent attached to a terminal the user can reconnect to. The article shows how to inspect process groups, sessions, and terminal ownership with ps to see what will be affected.

0
ProgrammingDEV Community ·

BLACKBOX Uses a FalkorDB Knowledge Graph to Give Incident Response a Memory

BLACKBOX is an AI-powered incident investigation agent designed for SRE and on-call teams. It uses FalkorDB as a persistent knowledge graph linking services, dependencies, alerts, deployments, runbooks, owners, and past postmortems. By traversing these connections, it can trace likely root causes, assess blast radius, and identify relevant experts with an explanation of the reasoning path. Findings from each investigation are written back into the graph, so future incidents with similar patterns can draw on stored context and reach answers faster. The developers argue that graph representation suits operational systems better than flat documents or isolated tables.

0
ProgrammingDEV Community ·

Success messages go unreviewed, and that is where many misleading UI strings hide

A commenter described a week spent trusting an SES 200 OK response, which only meant the email was accepted, not delivered, and the failure stayed invisible. The author argues error messages get scrutiny because annoyed users read them immediately, while success messages are written once and almost never reviewed. Such success text often overstates the outcome, reporting the server's step rather than the user's actual situation. The author suggests messages should state the user's state and next step, and that the best safeguard is to write the copy alongside the fix and pin it in tests, since style guidelines and linters cannot reliably catch misleading wording.

0
ProgrammingDEV Community ·

Anthropic Reportedly Seeks About $60B in Chip Financing With Over 10% Yield for Lenders

Anthropic is reportedly looking to raise roughly $60 billion in financing to fund chip purchases for its compute buildout. The AI company is said to be offering lenders, including Blackstone, a yield of over 10%. The report points to rising compute financing costs and growing interest from private credit as venture equity pulls back from such deals. The move reflects intensifying competition among AI firms to secure computing capacity. The details are drawn from reporting by the Financial Times and other outlets cited in the source article.