system/output: implement MessageError
All checks were successful
Test / Hakurei (push) Successful in 43s
Test / Create distribution (push) Successful in 26s
Test / Sandbox (push) Successful in 1m40s
Test / Hpkg (push) Successful in 3m35s
Test / Sandbox (race detector) (push) Successful in 4m24s
Test / Hakurei (race detector) (push) Successful in 5m20s
Test / Flake checks (push) Successful in 1m37s

This error is also formatted differently based on state.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2025-08-31 13:51:21 +09:00
parent 780e3e5465
commit b489a3bba1
2 changed files with 76 additions and 14 deletions

View File

@@ -20,16 +20,16 @@ func SetOutput(v container.Msg) {
// OpError is returned by [I.Commit] and [I.Revert].
type OpError struct {
Op string
Err error
Message string
Revert bool
Op string
Err error
Msg string
Revert bool
}
func (e *OpError) Unwrap() error { return e.Err }
func (e *OpError) Error() string {
if e.Message != "" {
return e.Message
if e.Msg != "" {
return e.Msg
}
switch {
@@ -47,6 +47,16 @@ func (e *OpError) Error() string {
}
}
func (e *OpError) Message() string {
switch {
case e.Msg != "":
return e.Error()
default:
return "cannot " + e.Error()
}
}
// newOpError returns an [OpError] without a message string.
func newOpError(op string, err error, revert bool) error {
if err == nil {
@@ -69,10 +79,18 @@ func printJoinedError(println func(v ...any), fallback string, err error) {
error
}
if !errors.As(err, &joinErr) {
println(fallback, err)
if m, ok := container.GetErrorMessage(err); ok {
println(m)
} else {
println(fallback, err)
}
} else {
for _, err = range joinErr.Unwrap() {
println(err.Error())
if m, ok := container.GetErrorMessage(err); ok {
println(m)
} else {
println(err.Error())
}
}
}
}