aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/output.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-08-31 13:51:21 +0900
committerOphestra <cat@gensokyo.uk>2025-08-31 13:51:21 +0900
commitb489a3bba15bc6d808d7cc9c17f74dd833d32b9e (patch)
tree4cf9ccf921a1e8fbb8e3d83da74631d35ca1034e /system/output.go
parent780e3e546581dd4a46b887310a665eea06f3279a (diff)
system/output: implement MessageError
This error is also formatted differently based on state. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/output.go')
-rw-r--r--system/output.go34
1 files changed, 26 insertions, 8 deletions
diff --git a/system/output.go b/system/output.go
index f3a4bc5c..e602976c 100644
--- a/system/output.go
+++ b/system/output.go
@@ -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())
+ }
}
}
}