mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-14 21:37:09 +02:00
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:
parent
29156d3053
commit
ceb0be482e
3 changed files with 5 additions and 3 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue