Code quality#20
Merged
Merged
Conversation
Add anyhow-based AppError type that implements IntoResponse, returning
a JSON {"message": "..."} body on error (consistent with the Laravel
API format). Add HtmlTemplate<T> wrapper that renders Askama templates
and falls back to AppError on render failure.
Refactor all handler functions to return Result<impl IntoResponse, AppError>
and use ? for error propagation instead of:
- .unwrap_or_default() / .unwrap_or(0) silently masking DB failures
- .expect() panics in api.rs (legacy_latest, latest_result, get_result)
- repeated match template.render() { Ok => ..., Err => 500 } blocks
Changes:
- Cargo.toml: add anyhow = "1"
- src/error.rs: new AppError + HtmlTemplate types
- src/lib.rs: wire in pub mod error
- src/handlers/{auth,dashboard,dashboard_admin,results,speedtest,tokens,profile,schedules}.rs
- src/api.rs
Enable five lints across all crate targets (lib.rs, main.rs, create-test-user.rs): - clippy::uninlined_format_args - clippy::unreadable_literal - clippy::unused_async - clippy::manual_let_else - clippy::match_same_arms Fix all existing violations: - src/error.rs, src/handlers/speedtest.rs: inline format args (auto-fixed) - src/i18n.rs: merge duplicate match arms into single arm per language - src/handlers/profile.rs: rewrite match-with-early-return as let...else - src/bin/create-test-user.rs: add _ separators to numeric literals - src/speedtest.rs: add #[allow(clippy::unused_async)] with a comment explaining that run_speedtest uses std::process::Command and should eventually migrate to tokio::process::Command
The [lints.clippy] table in Cargo.toml (added in the previous commit) is the idiomatic approach since Rust 1.81 and applies to all crate targets automatically.
* enable all-features * run an all targets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📃 Description
No longer silently ignore database errors.
Use 2024 Rust edition and fix clippy warnings.