Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/rust-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Rust release
on:
push:
branches: [main]
paths: ["rust/**"]
permissions:
contents: read
concurrency:
group: rust-release
cancel-in-progress: false
jobs:
# Publishing stays off until the repository variable RUST_RELEASE_ENABLED is
# "true". Trusted publishing needs each crate published once by hand first,
# then this workflow and the crates-io environment registered on crates.io.
release:
name: Publish released crates to crates.io
if: vars.RUST_RELEASE_ENABLED == 'true'
environment: crates-io
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
id-token: write
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
persist-credentials: false
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal
rustup default stable
- name: Exchange the OIDC token for a crates.io token
id: auth
uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5
- name: Publish with release-plz
uses: release-plz/action@1fb72a9583c3601c197b3bd6fc6ce50d58e28ef3 # v0.5.148
with:
command: release
manifest_path: rust/Cargo.toml
config: rust/release-plz.toml
version: 0.4.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

release-pr:
name: Open or update the Rust release pull request
if: vars.RUST_RELEASE_ENABLED == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
pull-requests: write
concurrency:
group: rust-release-pr
cancel-in-progress: false
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
persist-credentials: false
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal
rustup default stable
- name: Open the release pull request with release-plz
uses: release-plz/action@1fb72a9583c3601c197b3bd6fc6ce50d58e28ef3 # v0.5.148
with:
command: release-pr
manifest_path: rust/Cargo.toml
config: rust/release-plz.toml
version: 0.4.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
228 changes: 228 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
name: Rust CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
defaults:
run:
working-directory: rust
concurrency:
group: rust-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
CARGO_TERM_COLOR: always
CARGO_BUILD_WARNINGS: deny
CARGO_INCREMENTAL: "0"
MSRV: "1.88"
jobs:
# A pull request that changes nothing the Rust crates read skips every job
# below; skipped jobs still satisfy required checks.
changes:
name: Detect Rust changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
rust: ${{ steps.diff.outputs.rust }}
defaults:
run:
working-directory: .
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: List the changed paths
id: diff
env:
EVENT: ${{ github.event_name }}
BASE: ${{ github.event.pull_request.base.sha }}
run: |
if [ "$EVENT" != "pull_request" ]; then
echo "rust=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if git diff --name-only "$BASE"...HEAD | grep -qE '^(rust/|conformance/|\.github/workflows/rust)'; then
echo "rust=true" >> "$GITHUB_OUTPUT"
else
echo "rust=false" >> "$GITHUB_OUTPUT"
fi

release-age:
name: Refuse crate versions under 3 days old
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: 24
- name: Test the release-age check
run: node --test scripts/*.test.ts
- name: Check Cargo.lock
run: node scripts/release-age.ts

lint:
name: Format, clippy and docs
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal --component clippy,rustfmt
rustup default stable
- name: Cache build
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
with:
workspaces: rust
- name: Check formatting
run: cargo fmt --all --check
- name: Run clippy
run: cargo clippy --locked --workspace --all-targets --all-features -- -D warnings
- name: Build docs
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --locked --workspace --all-features --no-deps

test:
name: Test (${{ matrix.os }})
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest, windows-latest]
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal
rustup default stable
- name: Cache build
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
with:
workspaces: rust
- name: Run tests
run: cargo test --locked --workspace --all-features --all-targets
- name: Run doc tests
run: cargo test --locked --workspace --all-features --doc

features:
name: Check feature combinations
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal
rustup default stable
- name: Install cargo-hack
uses: taiki-e/install-action@43dc658ea8a4fa76c68a84c0acd17c34169b6e2a # v2.90.12
with:
tool: cargo-hack@0.6.46
- name: Cache build
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
with:
workspaces: rust
- name: Check every pair of features
run: >-
cargo hack check --locked --workspace --all-targets
--feature-powerset --depth 2

msrv:
name: Build on the minimum supported Rust version
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust ${{ env.MSRV }}
run: |
rustup toolchain install "$MSRV" --profile minimal
rustup default "$MSRV"
- name: Cache build
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
with:
workspaces: rust
- name: Check that rust-version matches the workspace
run: grep -qx "rust-version = \"$MSRV\"" Cargo.toml
- name: Build every crate with every feature
run: cargo check --locked --workspace --all-features

wasm:
name: Build for wasm32
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
rustup default stable
- name: Cache build
uses: Swatinem/rust-cache@63fed3e2fecf6f7b51dc6f043341b79ef82a9ae7 # v2.9.2
with:
workspaces: rust
- name: Build for wasm32-unknown-unknown
run: >-
cargo build --locked --workspace --target wasm32-unknown-unknown
--all-features

deny:
name: Check advisories, licenses and sources
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Clone repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install cargo-deny
uses: taiki-e/install-action@43dc658ea8a4fa76c68a84c0acd17c34169b6e2a # v2.90.12
with:
tool: cargo-deny@0.22.2
- name: Run cargo-deny
run: cargo deny --locked check

# One check for branch protection: fails when any Rust job failed or was
# cancelled, and passes when they all passed or were skipped.
gate:
name: Rust CI
needs: [changes, release-age, lint, test, features, msrv, wasm, deny]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
defaults:
run:
working-directory: .
steps:
- name: Fail when a Rust job failed
env:
RESULTS: ${{ join(needs.*.result, ' ') }}
run: |
echo "$RESULTS"
case " $RESULTS " in
*" failure "*|*" cancelled "*) exit 1 ;;
esac
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package per language.
| Directory | Package |
| ---------------------------- | --------------------------------------------------------------------------------------------------------- |
| [`typescript/`](typescript/) | [`@udibo/http-error`](typescript/README.md) on [npm](https://www.npmjs.com/package/@udibo/http-error) and [JSR](https://jsr.io/@udibo/http-error) |
| [`rust/`](rust/) | [`udibo-http-error`](rust/crates/udibo-http-error/README.md), not yet published to crates.io |

Each package is versioned and released on its own. `conformance/` will hold the test vectors every package must pass, so the
languages produce the same Problem Details for the same error.
Each package is versioned and released on its own. [`conformance/`](conformance/)
holds the test vectors every package must pass, so the languages produce the
same Problem Details for the same error.

## License

Expand Down
23 changes: 21 additions & 2 deletions conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ Three sections:
`expected` response or an `error`.
- `input` members are the error's options: `status`, `message`, `title`,
`detail`, `type`, `instance`, `extensions`, `headers` and `expose`. A
missing member means the option is not set.
missing member means the option is not set. A header's value is a string,
or a list of strings for a field sent more than once, in order.
- `expected.status` is the response status; `expected.expose` is the error's
`expose` value; `expected.headers` is the complete set of response headers,
names lowercased, one value per name (no case repeats a header);
names lowercased, each value a string, or a list of strings in order for a
field sent more than once (`set-cookie`);
`expected.body` is the JSON response body. Compare bodies as JSON values:
member order is not significant.
- `error: "invalid status"` means constructing the error must fail.
Expand All @@ -36,6 +38,14 @@ The rules the cases pin:
set, and so does an empty parsed `title` or `detail`.
- An extension named `type`, `status`, `title`, `detail` or `instance` is never
serialized. Any other member, `__proto__` included, is.
- JSON member names are case-sensitive: `Status` and `Title` are extensions,
never the problem's `status` or `title`, when parsing and serializing.
- A header field set more than once, such as `set-cookie`, keeps every value in
order.
- Extension values keep their JSON type and shape: an empty object stays an
object, an empty list stays a list, an object with keys `"0"` and `"1"` stays
an object, and `false`, `0` and `null` survive inside nested values. A title or
detail of `"0"` is set, not empty.
- `content-type` defaults to `application/problem+json`.
- Parsing ignores a leading UTF-8 byte-order mark. It takes the body's
`status` when it is a JSON number whose value is an integer from 400 to 599
Expand All @@ -46,3 +56,12 @@ The rules the cases pin:
detail is replaced by the default.
- A body that is not a JSON object with a non-null `status`, `title` or `type`
member gives an unexposed error with the default title and detail.

## Numbers in extensions

Every package exchanges integers from -9007199254740991 through
9007199254740991 exactly (the I-JSON range, RFC 7493 §2.2). Outside that range
a package may lose precision: carry a larger ID or counter as a decimal string,
which every package passes through unchanged. A package keeps the caller's JSON
type: it never quotes a number it received, and never rounds one to imitate
another language. The vectors use only integers inside the range.
Loading
Loading