refactor(artwork): make the trace nil-safe in one place only

add already handles a nil trace, so record's own guard was dead; Steps was the
odd one out and would panic where every other method tolerates nil.
This commit is contained in:
Deluan committed 2026-08-14 15:13:55 -04:00
1 parent 29156d3053
commit ceb0be482e
3 files changed
+5 -3

No files matched your search

+1 -3
View File
@@ -56,9 +56,7 @@ func (c *chainState) try(candidate string, res resolution, ok bool) (resolution,
}
func (c *chainState) record(candidate string, out Outcome, detail string) {
if c.trace != nil {
c.trace.add(traceStep{Candidate: candidate, Outcome: out, Detail: detail})
}
c.trace.add(traceStep{Candidate: candidate, Outcome: out, Detail: detail})
}
// exhausted is the outcome when no source in the chain yielded an image.
+3
View File
@@ -52,6 +52,9 @@ func (t *chainTrace) add(step traceStep) {
}
func (t *chainTrace) Steps() []traceStep {
if t == nil {
return nil
}
t.mu.Lock()
defer t.mu.Unlock()
return slices.Clone(t.steps)
+1
View File
@@ -56,6 +56,7 @@ var _ = Describe("chainTrace", func() {
It("does not panic when the trace is nil", func() {
var t *chainTrace
Expect(func() { t.add(traceStep{Candidate: "cover.*", Outcome: OutcomeMiss}) }).ToNot(Panic())
Expect(t.Steps()).To(BeEmpty(), "a nil trace collects nothing, so reading it must be as safe as writing it")
})
It("is safe to use concurrently", func() {