Skip to content

feat(rust): add the udibo-http-error crate - #22

Merged
KyleJune merged 8 commits into
mainfrom
claude/project-thread-uz7ea9
Dec 5, 2026
Merged

KyleJune merged 8 commits into
mainfrom
claude/project-thread-uz7ea9

Conversation

@KyleJune

@KyleJune KyleJune commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Requested by Kyle · project thread

Summary

Adds rust/, a Cargo workspace with the udibo-http-error crate, the Rust counterpart of @udibo/http-error. It passes the shared conformance/vectors/problem-details.json, so both languages produce the same problem details for the same error. Closes #19 apart from publishing, which waits for a crates.io account.

API

  • HttpError::builder() with status (a u16 or http::StatusCode), message, title, detail, problem_type, instance, extension(s), header(s), expose and source. build() returns InvalidStatus outside 400 to 599.
  • Shortcuts: HttpError::not_found(msg), bad_request, unauthorized, forbidden, conflict, unprocessable_content, too_many_requests, internal, service_unavailable, plus HttpError::new(status, msg).
  • HttpError::from_error(err) turns an unexpected failure into an unexposed 500 that keeps it as the source.
  • HttpError::from_problem_body(status, bytes) reads another service's problem response, by the same parse rules as the TypeScript package's HttpError.from(response).
  • ProblemDetails serializes with serde and never lets an extension replace a standard member.
  • default_title(status) and default_detail(status) give the same table as TypeScript.
  • Feature axum: impl IntoResponse for HttpError.

The member rules match TypeScript exactly. HttpError implements std::error::Error and Clone, and the crate builds for wasm32-unknown-unknown.

Shared vectors added

These come from the Go port spike.

  • Two parse cases and one serialize case pin that JSON member names are case-sensitive. Status and Title stay extensions and never become status or title.
  • One serialize case sends a repeated Set-Cookie header, and both values must come back in order.
    • To support it, the vector format accepts a list of strings for a repeated header field.
    • Both the TypeScript and Rust vector readers now compare every value of a repeated field. The old TypeScript reader used Object.fromEntries, which kept only the last value. Restoring it makes the new case fail.
  • An axum test checks that IntoResponse keeps repeated headers.

From the PHP spike, one parse case and one serialize case check that extension JSON shapes survive. They cover {}, [], an object keyed "0"/"1", nested false/0/null, a string ID above 2^53, and a title and detail of "0".

The conformance README now states the number contract:

  • Integers in the I-JSON range are exchanged exactly.
  • Larger values travel as decimal strings.
  • No package quotes a number or rounds it to imitate another language.

The crate README says the same. The TypeScript README is left for a separate docs: commit, because a change to it inside this feat squash would cut a TypeScript release.

No published TypeScript file changes, so this cuts no TypeScript release.

CI and release

.github/workflows/rust.yml copies oauth2's gates:

  • fmt, clippy and docs;
  • tests on Linux x64 and arm, macOS and Windows;
  • a cargo-hack feature powerset;
  • MSRV 1.88 and a wasm32 build;
  • cargo-deny and the 3-day release-age check;
  • one Rust CI gate job.

rust/.cargo/config.toml sets global-min-publish-age = "3 days".

rust-release.yml runs release-plz with the tag udibo-http-error-v<version>. It is off until RUST_RELEASE_ENABLED is set. Rust-only commits change neither TypeScript CI (path filter) nor TypeScript releases (the release plugin counts only typescript/ and conformance/).

Known red until 2026-12-05 16:29 UTC: the release-age job refuses pin-project-lite 0.2.19, published 2026-12-02. axum-core needs it, and every earlier version has been yanked, so cargo-deny refuses those instead. It ages past 3 days tomorrow afternoon, and CI will be re-run then. No exemption was added.

Testing

Run locally from rust/, each passing:

  • cargo fmt --check
  • clippy -D warnings
  • cargo doc with -D warnings
  • cargo test --all-features: 3 conformance tests over 26 serialize, 22 parse and 200 defaults cases; 14 behavior tests; 3 axum tests; 10 doc tests, including the crate README
  • cargo hack --feature-powerset --depth 2
  • cargo +1.88 check
  • the wasm32 build
  • cargo deny check
  • node --test scripts/*.test.ts

Mutation checks:

  • Letting an unexposed message become the detail fails the conformance tests.
  • Treating null members as making a body a problem also fails them.

Related Issues

Closes #19. Part of udibo/oauth2#275.

https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS


Generated by Claude Code

Add a Cargo workspace in rust/ with the udibo-http-error crate: HttpError
with a builder and status shortcuts, ProblemDetails, the default title and
detail of every status, parsing of another service's problem response,
and IntoResponse behind the axum feature. It passes the shared
conformance vectors.

CI copies oauth2's Rust gates: fmt, clippy, docs, tests on four
platforms, a cargo-hack feature matrix, MSRV 1.88, a wasm32 build,
cargo-deny and a 3-day release-age check, behind one Rust CI job.
Publishing through release-plz stays off until RUST_RELEASE_ENABLED is
set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
@KyleJune KyleJune self-assigned this Dec 4, 2026
The workflow policy test let only ci.yml's release job use an
environment or mint an OIDC token. Add rust-release.yml's release job,
and pin that it uses the crates-io environment and runs only once
RUST_RELEASE_ENABLED is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS

KyleJune commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Refuse crate versions under 3 days old fails because pin-project-lite 0.2.19 (needed by axum-core) was published 2026-12-02 16:29 UTC. Every older version is yanked, so cargo-deny refuses those. The check passes once 0.2.19 is three days old (2026-12-05 16:29 UTC); I will re-run it then rather than add an exemption.

The TypeScript test failures on ff56e6e came from the workflow policy test, which allowed only the npm release job an environment and OIDC token. 6f75b42 adds the crates.io release job to it.


Generated by Claude Code

Add vectors for problem members that differ from a standard member only
by case (kept as extensions when parsing and serializing) and for a
repeated Set-Cookie response header. A vector header value may now be a
list of strings for a field sent more than once. The TypeScript and Rust
vector readers build and compare every value of a repeated field instead
of keeping the last one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
Add a parse and a serialize vector carrying an empty object, an empty
list, an object keyed "0" and "1", nested false/0/null values, a string
ID beyond 2^53, and a title and detail of "0". Document that every
package exchanges integers in the I-JSON range exactly, that larger IDs
travel as decimal strings, and that no package quotes or rounds a
number to match another language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
Replace the two rows rebuilt from the spike's description with the
candidate rows it published (handoffs/port-spikes/php/candidate-vectors.json
in udibo at db369a7). They cover the same shapes; the precision
observation stays out of the vectors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPqZepyt7atNAZ12qoUeVS
@KyleJune
KyleJune marked this pull request as ready for review December 5, 2026 16:36
@KyleJune
KyleJune merged commit cbb1c1d into main Dec 5, 2026
42 of 44 checks passed
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.13.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create the udibo-http-error Rust crate

2 participants