aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/output.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-13 01:15:19 +0900
committerOphestra <cat@gensokyo.uk>2025-11-13 01:17:47 +0900
commit4e7aab07d5b175345fdf3ea08868dab1e6d90126 (patch)
treea625cca0e8cdf576313fe2d9ab07a22d1839ee7c /system/output.go
parent15a66a2b314e7a674c9445e25ffb2451ec73b55e (diff)
internal/system: relocate from system
These packages are highly specific to hakurei and are difficult to use safely from other pieces of code. Their exported symbols are made available until v0.4.0 where they will be removed for #24. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'system/output.go')
-rw-r--r--system/output.go88
1 files changed, 0 insertions, 88 deletions
diff --git a/system/output.go b/system/output.go
deleted file mode 100644
index 71acace4..00000000
--- a/system/output.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package system
-
-import (
- "errors"
- "net"
- "os"
-
- "hakurei.app/container"
- "hakurei.app/message"
-)
-
-// OpError is returned by [I.Commit] and [I.Revert].
-type OpError struct {
- Op string
- Err error
- Msg string
- Revert bool
-}
-
-func (e *OpError) Unwrap() error { return e.Err }
-func (e *OpError) Error() string {
- if e.Msg != "" {
- return e.Msg
- }
-
- switch {
- case errors.As(e.Err, new(*os.PathError)),
- errors.As(e.Err, new(*os.LinkError)),
- errors.As(e.Err, new(*net.OpError)),
- errors.As(e.Err, new(*container.StartError)):
- return e.Err.Error()
-
- default:
- if !e.Revert {
- return "apply " + e.Op + ": " + e.Err.Error()
- } else {
- return "revert " + e.Op + ": " + e.Err.Error()
- }
- }
-}
-
-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 {
- return nil
- }
- return &OpError{op, err, "", revert}
-}
-
-// newOpErrorMessage returns an [OpError] with an overriding message string.
-func newOpErrorMessage(op string, err error, message string, revert bool) error {
- if err == nil {
- return nil
- }
- return &OpError{op, err, message, revert}
-}
-
-func printJoinedError(println func(v ...any), fallback string, err error) {
- var joinErr interface {
- Unwrap() []error
- error
- }
- if !errors.As(err, &joinErr) {
- if m, ok := message.GetMessage(err); ok {
- println(m)
- } else {
- println(fallback, err)
- }
- } else {
- for _, err = range joinErr.Unwrap() {
- if m, ok := message.GetMessage(err); ok {
- println(m)
- } else {
- println(err.Error())
- }
- }
- }
-}