refuse to update spooldb with negative total or filament weights

This commit is contained in:
Ian Gulliver
2026-06-07 22:10:55 -07:00
parent f0809220e8
commit 9d0f570c85
2 changed files with 8 additions and 3 deletions
+8
View File
@@ -217,6 +217,10 @@ func processImg(img image.Image, name string, auth claude.Auth, dryRun bool) res
r.Error = fmt.Sprintf("scale is set to imperial units (%s); switch it to grams", reading.Unit)
return r
}
if reading.Weight < 0 {
r.Error = fmt.Sprintf("scale read a negative weight (%g g); refusing to update", reading.Weight)
return r
}
r.Unit = reading.Unit
r.Confidence = ptr(reading.Confidence)
r.VoteWeights = reading.Weights
@@ -228,6 +232,10 @@ func processImg(img image.Image, name string, auth claude.Auth, dryRun bool) res
if info != nil {
r.NewWeight.Spool = ptr(info.EmptySpoolGrams)
r.NewWeight.Filament = ptr(reading.Weight - info.EmptySpoolGrams)
if reading.Weight-info.EmptySpoolGrams < 0 {
r.Error = fmt.Sprintf("measured total %g g is below the empty-spool weight %g g (negative filament); refusing to update", reading.Weight, info.EmptySpoolGrams)
return r
}
}
// Write the measured total back when it differs from the site's total — the