SShortSingh.
Back to feed

Go Library Checker Adds RFC 9457 Problem Details Support for Validation Errors

0
·4 views

The Go validation library Checker has introduced a ProblemDetails() method that converts struct-tag validation failures into RFC 9457-compliant 'application/problem+json' responses. RFC 9457, an IETF standard for HTTP API error reporting, defines a structured body with fields like type, title, status, and an invalid-params array detailing which fields failed and why. Previously, Go APIs typically returned custom, inconsistent error shapes that clients had to learn individually from documentation. With a single method call on a CheckErrors value, developers can now produce a standards-compliant error response with sensible defaults, including HTTP 400 status and machine-readable error codes. The method also supports localization across 23 languages and allows overriding default fields such as type, title, and status before marshaling.

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 ·

7 Silent Ways Scheduled Automation Jobs Fake Success With Exit Code 0

A developer running 30 scheduled automation jobs on a single Windows machine discovered that every failure over three months had falsely reported success, with the task scheduler consistently showing exit code 0. Root causes included a VBScript launcher discarding return values, a batch file where an echo command overwrote the real exit code, and a Flask service crashing silently at startup because pythonw.exe lacks a usable stdout stream. Windows Task Scheduler's default settings also caused silent failures, as jobs were quietly skipped or killed when the laptop ran on battery or when the user interacted with the machine. The developer's key takeaway is that exit codes alone are unreliable indicators of job success, and teams should instead verify that expected output artifacts were actually produced. Each failure mode required a targeted fix at its specific layer, from correcting VBScript syntax to overriding Task Scheduler's power and idle defaults.

0
ProgrammingDEV Community ·

checkerlint Catches Faulty Go Struct Validation Tags Before Runtime

A new static analysis tool called checkerlint addresses a silent failure risk in Go programs where malformed struct validation tags compile successfully but crash or misbehave at runtime. The tool, built on Go's go/analysis framework, scans checker struct tags at build or lint time to flag three categories of errors: unknown checker names, type-incompatible checker usage, and cross-field references pointing to non-existent fields. For example, applying an email checker to an integer field or referencing a misspelled sibling field will now produce a build-time error rather than a runtime panic. checkerlint can be run as a standalone binary, plugged into go vet, or integrated as a custom linter within golangci-lint v2. It automatically stays in sync with whichever version of the github.com/cinar/checker/v2 library a project uses, though it cannot detect checkers registered dynamically at runtime or via non-literal expressions.

0
ProgrammingDEV Community ·

Open-Source Tool ZGLanguage Automates Bulk SQL PIVOT Syntax Conversion

Database migration projects frequently run into SQL syntax incompatibilities across different platforms, making manual code rewrites slow and error-prone. The open-source tool ZGLanguage offers an automated solution for converting large volumes of SQL code in batch. A practical example demonstrates how a standard SQL PIVOT function can be automatically rewritten into equivalent CASE-WHEN conditional aggregation logic. The tool applies user-defined conversion rules to parse and transform the original query structure, producing a functionally identical result compatible with target database systems. This approach aims to reduce human effort and minimize errors when migrating substantial codebases between database environments.

0
ProgrammingDEV Community ·

Puzzle Generator Rejects 99.7% of Output by Design, Solves 5 in 84ms

A software developer built a Go CLI tool called verigen that generates cryptarithmetic puzzles, where letters represent unique digits forming valid sums. The tool deliberately makes no correctness guarantees at the generation stage, offloading all validation to a separate verifier that performs exhaustive searches. Out of 1,947 attempts, only 5 puzzles pass, with rejections split across no unique solution (39.55%), no solution (35.70%), and exceeding 10 distinct letters (24.50%). Despite the 0.26% acceptance rate, the entire process completes in just 84 milliseconds, making brute-force generation more practical than building a smarter generator. The developer argues this generator-verifier split is especially relevant when the generator is a large language model, where improving output quality is costly but running a fast verifier thousands of times is not.