refuse to update spooldb with negative total or filament weights
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user