Skip to content

Code quality#20

Merged
avdv merged 9 commits into
mainfrom
code-quality
Jun 28, 2026
Merged

Code quality#20
avdv merged 9 commits into
mainfrom
code-quality

Conversation

@avdv

@avdv avdv commented Jun 28, 2026

Copy link
Copy Markdown
Owner

📃 Description

No longer silently ignore database errors.

Use 2024 Rust edition and fix clippy warnings.

avdv added 9 commits June 28, 2026 13:59
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
@avdv
avdv merged commit 4e3d8e4 into main Jun 28, 2026
8 checks passed
@avdv
avdv deleted the code-quality branch June 28, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant