mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-29 04:07:12 -06:00
Robustness: VectorCraft never crashes — no panics in shipped code
Shipped code no longer unwraps, expects or panics: every one of the 124 unwrap()/expect()/panic!/unreachable! sites outside tests now handles the failure (Result/Option, ?, let-else, defaults) and reports errors to the user. - Lints: workspace clippy denies unwrap_used, expect_used, panic, todo, unimplemented and unreachable; clippy.toml allows them in tests, and integration tests, examples and testkit opt out explicitly. - Safety net (vectorcraft_engine::guard): a panic in a top-level command rolls the document back and returns EngineError::Internal; a panicking tool is reset; the MCP server answers with an internal error and keeps serving; the UI frame and each control request are guarded. - APIs that hid failures now return them: Rendered::to_png/to_jpeg/to_webp return Result (JPEG/WebP errors used to write empty files), FontDb::face returns Option, Region::top returns Option. - Fuzzing: engine/tests/import_fuzz.rs feeds garbage, hostile and mutated SVG and PDF through import → render → export (30k cases locally, no panics). - Docs: AGENTS.md/CLAUDE.md rule, docs/development.md "Robustness" section, README pointer and a PR template checklist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Opus 5.5
parent
0f241aac9f
commit
3e323bfa2a
@@ -204,7 +204,7 @@ impl Mesh {
|
||||
|
||||
/// Band width (in vertices) of the vertex adjacency.
|
||||
fn vertex_band(&self) -> usize {
|
||||
self.tris.iter().map(|t| t.iter().max().unwrap() - t.iter().min().unwrap()).max().unwrap_or(0)
|
||||
self.tris.iter().filter_map(|t| Some(t.iter().max()? - t.iter().min()?)).max().unwrap_or(0)
|
||||
}
|
||||
|
||||
/// The triangle and barycentric coordinates of `p` (extrapolated from the nearest mesh cell
|
||||
@@ -448,18 +448,18 @@ pub fn auto_pins(mesh: &Mesh, count: usize) -> Vec<Point> {
|
||||
return vec![];
|
||||
}
|
||||
let c = centres.iter().fold(Vec2::ZERO, |a, p| a + p.to_vec2()) / centres.len() as f64;
|
||||
let first = *centres.iter().min_by(|a, b| a.distance_squared(c.to_point()).total_cmp(&b.distance_squared(c.to_point()))).unwrap();
|
||||
let Some(&first) = centres.iter().min_by(|a, b| a.distance_squared(c.to_point()).total_cmp(&b.distance_squared(c.to_point()))) else {
|
||||
return vec![];
|
||||
};
|
||||
let mut out = vec![first];
|
||||
while out.len() < count.min(centres.len()) {
|
||||
let next = centres
|
||||
.iter()
|
||||
.max_by(|a, b| {
|
||||
let da = out.iter().map(|o| o.distance_squared(**a)).fold(f64::MAX, f64::min);
|
||||
let db = out.iter().map(|o| o.distance_squared(**b)).fold(f64::MAX, f64::min);
|
||||
da.total_cmp(&db)
|
||||
})
|
||||
.copied()
|
||||
.unwrap();
|
||||
let Some(&next) = centres.iter().max_by(|a, b| {
|
||||
let da = out.iter().map(|o| o.distance_squared(**a)).fold(f64::MAX, f64::min);
|
||||
let db = out.iter().map(|o| o.distance_squared(**b)).fold(f64::MAX, f64::min);
|
||||
da.total_cmp(&db)
|
||||
}) else {
|
||||
break;
|
||||
};
|
||||
out.push(next);
|
||||
}
|
||||
out
|
||||
|
||||
@@ -218,8 +218,9 @@ pub fn dabs(points: &[Point], spacing: f64) -> Vec<Point> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let end = *points.last().unwrap();
|
||||
if end.distance(last) > spacing * 0.25 {
|
||||
if let Some(&end) = points.last()
|
||||
&& end.distance(last) > spacing * 0.25
|
||||
{
|
||||
out.push(end);
|
||||
}
|
||||
out
|
||||
|
||||
@@ -128,10 +128,12 @@ impl Tool for AnchorTool {
|
||||
*began = true;
|
||||
}
|
||||
}
|
||||
out.push(match self.state {
|
||||
State::Convert { id, si, ai, .. } => {
|
||||
Action::Preview("path.convertAnchor".into(), json!({"id": id.0, "subpath": si, "anchor": ai, "to": "smooth", "x": p.x, "y": p.y}))
|
||||
}
|
||||
let preview = match self.state {
|
||||
State::Idle => return out,
|
||||
State::Convert { id, si, ai, .. } => Action::Preview(
|
||||
"path.convertAnchor".into(),
|
||||
json!({"id": id.0, "subpath": si, "anchor": ai, "to": "smooth", "x": p.x, "y": p.y}),
|
||||
),
|
||||
State::Handle { id, si, ai, out, .. } => Action::Preview(
|
||||
"path.setHandle".into(),
|
||||
json!({"id": id.0, "subpath": si, "anchor": ai, "which": if out { "out" } else { "in" }, "x": p.x, "y": p.y, "independent": true}),
|
||||
@@ -140,8 +142,8 @@ impl Tool for AnchorTool {
|
||||
"path.reshapeSegment".into(),
|
||||
json!({"id": id.0, "subpath": si, "segment": seg, "t": t, "dx": p.x - start.x, "dy": p.y - start.y}),
|
||||
),
|
||||
State::Idle => unreachable!(),
|
||||
});
|
||||
};
|
||||
out.push(preview);
|
||||
out
|
||||
}
|
||||
("anchorPoint", PointerKind::Up) => {
|
||||
|
||||
@@ -137,9 +137,8 @@ impl TypeTool {
|
||||
}
|
||||
if self.typing.is_none() {
|
||||
out.push(Action::Begin("Typing".into()));
|
||||
self.typing = Some(Typing { base: t.runs.clone(), cur: t.runs.clone() });
|
||||
}
|
||||
let ty = self.typing.as_mut().expect("typing session");
|
||||
let ty = self.typing.get_or_insert_with(|| Typing { base: t.runs.clone(), cur: t.runs.clone() });
|
||||
let len = edit::runs_len(&ty.cur);
|
||||
let (a, b) = (self.caret.min(self.anchor).min(len), self.caret.max(self.anchor).min(len));
|
||||
let caret = match &styled {
|
||||
|
||||
Reference in New Issue
Block a user