Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added serde_debugging feature #5

Merged
merged 2 commits into from
Jul 21, 2024
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
99 changes: 85 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,127 @@ name: Rust CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
test:
name: Test
lint:
name: Lint
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
rust:
toolchain:
- stable
- beta
- nightly
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.toolchain != 'stable' }}
steps:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Rust Toolchain
- name: Install Stable Rust Toolchain
if: matrix.toolchain == 'stable'
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Install Beta Rust Toolchain
if: matrix.toolchain == 'beta'
uses: dtolnay/rust-toolchain@beta
with:
components: rustfmt, clippy

- name: Install Nightly Rust Toolchain
if: matrix.toolchain == 'nightly'
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy

- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2

- name: Display Toolchain Information
run: |
cargo --version --verbose
rustc --version
rustc --version --verbose
cargo clippy --version

- name: Lint
- name: Format Check
run: |
cargo fmt -- --check

- name: Lint
run: |
cargo clippy -- -D warnings

- name: Dry Publish
uses: katyo/publish-crates@v2
with:
dry-run: true
ignore-unpublished-changes: true

test:
name: Test
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
features:
- default
- serde_debugging
toolchain:
- stable
- beta
- nightly
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.toolchain != 'stable' }}
steps:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Stable Rust Toolchain
if: matrix.toolchain == 'stable'
uses: dtolnay/rust-toolchain@stable

- name: Install Beta Rust Toolchain
if: matrix.toolchain == 'beta'
uses: dtolnay/rust-toolchain@beta

- name: Install Nightly Rust Toolchain
if: matrix.toolchain == 'nightly'
uses: dtolnay/rust-toolchain@nightly

- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2

- name: Display Toolchain Information
run: |
cargo --version --verbose
rustc --version --verbose

- name: Test
if: matrix.features == 'default'
run: |
cargo check
cargo test --all

- name: Test
if: matrix.features != 'default'
run: |
cargo check --features ${{ matrix.features }}
cargo test --all --features ${{ matrix.features }}

- name: Build
if: matrix.features == 'default'
run: |
cargo build --release

- name: Dry Publish
uses: katyo/publish-crates@v2
with:
dry-run: true
ignore-unpublished-changes: true
- name: Build
if: matrix.features != 'default'
run: |
cargo build --release --features ${{ matrix.features }}
4 changes: 2 additions & 2 deletions .github/workflows/live_endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:

- name: Live Endpoint Test
run: |
cargo check
cargo test --verbose --lib live
cargo check --features serde_debugging
cargo test --verbose --features serde_debugging --test live_endpoint_canary
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ include = [
"/LICENSE"
]

[features]
serde_debugging = ["dep:serde_path_to_error"]

[dependencies]
reqwest = { version = "0.12.4", features = ["json"] }
serde_json = "1.0.117"
serde = { version = "1.0.203", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] }
thiserror = "1.0.61"
serde_path_to_error = { version = "0.1.16", optional = true }

[dev-dependencies]
mockito = "1.4.0"
tokio = { version = "1.38.0", features = ["full"] }
serde_path_to_error = "0.1.16"
anyhow = "1.0.86"

[[example]]
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
662-27 train is heading to New York Penn, currently enroute to Parkesburg with an ETA of 2 minutes
```

## Features

- `serde_debugging` (Disabled by default): Enables the the following functions:
`trains_with_debugging`, `train_with_debugging`, `stations_with_debugging`,
`station_with_debugging`. These functions will operate the exact same way as
their counterparts with the exception that deserialization is completed using
[`serde_path_to_error`](https://crates.io/crates/serde_path_to_error) adapter.
This crate will print out the path of the offending field if deserialization
were to fail. The only quarky behavior is that instead of returning
`Error::DeserializeFailed`, the debugging functions will instead return
`Error:Other`. This is so that we can include the JSON response in the error
as well as the path to the field that caused the deserialization to fail,
making debugging a lot easier.

## Authors

Stefan Bossbaly
Expand Down
2 changes: 2 additions & 0 deletions amtrak-api.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
],
"settings": {
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.features": ["", "serde_debugging"],
"rust-analyzer.check.features": ["", "serde_debugging"],
"editor.formatOnSave": true
},
"launch": {
Expand Down
Loading
Loading