Ophestra 9963e7eba2
Some checks failed
Test / Create distribution (push) Successful in 34s
Test / Hakurei (push) Failing after 1m5s
Test / Sandbox (push) Failing after 1m28s
Test / Hpkg (push) Failing after 1m53s
Test / Hakurei (race detector) (push) Failing after 2m8s
Test / Sandbox (race detector) (push) Failing after 3m33s
Test / Flake checks (push) Has been skipped
system: wrap op errors
This passes more information allowing for better error handling. This eliminates generic WrapErr from system.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2025-08-30 23:27:22 +09:00

35 lines
703 B
Go

package container
import (
"log"
"sync/atomic"
)
type Msg interface {
IsVerbose() bool
Verbose(v ...any)
Verbosef(format string, v ...any)
Suspend()
Resume() bool
BeforeExit()
}
type DefaultMsg struct{ inactive atomic.Bool }
func (msg *DefaultMsg) IsVerbose() bool { return true }
func (msg *DefaultMsg) Verbose(v ...any) {
if !msg.inactive.Load() {
log.Println(v...)
}
}
func (msg *DefaultMsg) Verbosef(format string, v ...any) {
if !msg.inactive.Load() {
log.Printf(format, v...)
}
}
func (msg *DefaultMsg) Suspend() { msg.inactive.Store(true) }
func (msg *DefaultMsg) Resume() bool { return msg.inactive.CompareAndSwap(true, false) }
func (msg *DefaultMsg) BeforeExit() {}