server: compute onboarding progress percent in Rust (ultra-fuzz Run #1 UX LOW)
The onboarding template computed `completed * 100 / total` inline, which
would panic the render (a 500) if `total` ever became 0. Compute a guarded
progress_pct (checked_div) in build_onboarding_checklist and render that.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
3 files changed,
+11 insertions,
-2 deletions
| 56 |
56 |
|
];
|
| 57 |
57 |
|
let completed = steps.iter().filter(|s| s.done).count();
|
| 58 |
58 |
|
let total = steps.len();
|
| 59 |
|
- |
OnboardingChecklist { steps, completed, total }
|
|
59 |
+ |
// Guard the division here so the template never does arithmetic that could
|
|
60 |
+ |
// panic the render (total is steps.len() = nonzero today, but the guard
|
|
61 |
+ |
// keeps a future dynamic step list from turning a 0 into a 500).
|
|
62 |
+ |
let progress_pct = (completed * 100).checked_div(total).unwrap_or(0) as u32;
|
|
63 |
+ |
OnboardingChecklist { steps, completed, total, progress_pct }
|
| 60 |
64 |
|
}
|
| 61 |
65 |
|
|
| 62 |
66 |
|
/// Render the main user dashboard with projects and transactions.
|
| 74 |
74 |
|
pub steps: Vec<OnboardingStep>,
|
| 75 |
75 |
|
pub completed: usize,
|
| 76 |
76 |
|
pub total: usize,
|
|
77 |
+ |
/// Completion percentage, computed in Rust with a divide-by-zero guard
|
|
78 |
+ |
/// (ultra-fuzz Run #1 UX LOW). The template renders this directly rather
|
|
79 |
+ |
/// than doing `completed * 100 / total`, which would panic the render — a
|
|
80 |
+ |
/// 500 — if `total` ever became 0.
|
|
81 |
+ |
pub progress_pct: u32,
|
| 77 |
82 |
|
}
|
| 78 |
83 |
|
|
| 79 |
84 |
|
/// A sync app row for the SyncKit dashboard tab.
|
| 9 |
9 |
|
class="btn-tiny">Hide for now</button>
|
| 10 |
10 |
|
</div>
|
| 11 |
11 |
|
<div class="progress-bar-container progress-bar-container--slim mb-4">
|
| 12 |
|
- |
<div class="progress-bar progress-bar--highlight" style="width: {{ checklist.completed * 100 / checklist.total }}%;"></div>
|
|
12 |
+ |
<div class="progress-bar progress-bar--highlight" style="width: {{ checklist.progress_pct }}%;"></div>
|
| 13 |
13 |
|
</div>
|
| 14 |
14 |
|
{% for step in checklist.steps %}
|
| 15 |
15 |
|
<div class="checklist-row">
|