aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/hlog
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-09-12 06:46:12 +0900
committerOphestra <cat@gensokyo.uk>2025-09-12 06:52:35 +0900
commitf8760438446ee4210a479402d91018ad610bcf34 (patch)
treeab8b3a1cbf69d2c2f42531fd786a480ca87f889e /internal/hlog
parent6265aea73a5f4933f4837bc1298c22fcd39b6f4f (diff)
internal/hlog: remove error wrapping
This was a stopgap solution that lasted for way too long. This finally removes it and prepares internal/app for some major changes. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/hlog')
-rw-r--r--internal/hlog/errors.go81
-rw-r--r--internal/hlog/msg.go14
2 files changed, 6 insertions, 89 deletions
diff --git a/internal/hlog/errors.go b/internal/hlog/errors.go
deleted file mode 100644
index d731f57f..00000000
--- a/internal/hlog/errors.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package hlog
-
-import (
- "fmt"
- "log"
- "reflect"
- "strings"
-)
-
-// baseError implements a basic error container
-type baseError struct {
- Err error
-}
-
-func (e *baseError) Error() string { return e.Err.Error() }
-func (e *baseError) Unwrap() error { return e.Err }
-
-// BaseError implements an error container with a user-facing message
-type BaseError struct {
- message string
- baseError
-}
-
-// Message returns a user-facing error message
-func (e *BaseError) Message() string { return e.message }
-
-// WrapErr wraps an error with a corresponding message.
-func WrapErr(err error, a ...any) error {
- if err == nil {
- return nil
- }
- return wrapErr(err, fmt.Sprintln(a...))
-}
-
-// WrapErrSuffix wraps an error with a corresponding message with err at the end of the message.
-func WrapErrSuffix(err error, a ...any) error {
- if err == nil {
- return nil
- }
- return wrapErr(err, fmt.Sprintln(append(a, err)...))
-}
-
-// WrapErrFunc wraps an error with a corresponding message returned by f.
-func WrapErrFunc(err error, f func(err error) string) error {
- if err == nil {
- return nil
- }
- return wrapErr(err, f(err))
-}
-
-func wrapErr(err error, message string) *BaseError {
- return &BaseError{message, baseError{err}}
-}
-
-var (
- baseErrorType = reflect.TypeFor[*BaseError]()
-)
-
-func AsBaseError(err error, target **BaseError) bool {
- v := reflect.ValueOf(err)
- if !v.CanConvert(baseErrorType) {
- return false
- }
-
- *target = v.Convert(baseErrorType).Interface().(*BaseError)
- return true
-}
-
-func PrintBaseError(err error, fallback string) {
- var e *BaseError
-
- if AsBaseError(err, &e) {
- if msg := e.Message(); strings.TrimSpace(msg) != "" {
- log.Print(msg)
- return
- }
- Verbose("*"+fallback, err)
- return
- }
- log.Println(fallback, err)
-}
diff --git a/internal/hlog/msg.go b/internal/hlog/msg.go
index dd37fdbf..753f6428 100644
--- a/internal/hlog/msg.go
+++ b/internal/hlog/msg.go
@@ -2,11 +2,9 @@ package hlog
type Output struct{}
-func (Output) IsVerbose() bool { return Load() }
-func (Output) Verbose(v ...any) { Verbose(v...) }
-func (Output) Verbosef(format string, v ...any) { Verbosef(format, v...) }
-func (Output) WrapErr(err error, a ...any) error { return WrapErr(err, a...) }
-func (Output) PrintBaseErr(err error, fallback string) { PrintBaseError(err, fallback) }
-func (Output) Suspend() { Suspend() }
-func (Output) Resume() bool { return Resume() }
-func (Output) BeforeExit() { BeforeExit() }
+func (Output) IsVerbose() bool { return Load() }
+func (Output) Verbose(v ...any) { Verbose(v...) }
+func (Output) Verbosef(format string, v ...any) { Verbosef(format, v...) }
+func (Output) Suspend() { Suspend() }
+func (Output) Resume() bool { return Resume() }
+func (Output) BeforeExit() { BeforeExit() }