summaryrefslogtreecommitdiffstats
path: root/internal/internal.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
commitb09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch)
treed2caec2610d4ea887803ec9e9c3cd77136c448ba /internal/internal.go
parentInitial commit. (diff)
downloadicingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz
icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'internal/internal.go')
-rw-r--r--internal/internal.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/internal.go b/internal/internal.go
new file mode 100644
index 0000000..7352d40
--- /dev/null
+++ b/internal/internal.go
@@ -0,0 +1,48 @@
+package internal
+
+import (
+ "encoding/json"
+ "github.com/pkg/errors"
+)
+
+// CantDecodeHex wraps the given error with the given string that cannot be hex-decoded.
+func CantDecodeHex(err error, s string) error {
+ return errors.Wrapf(err, "can't decode hex %q", s)
+}
+
+// CantParseFloat64 wraps the given error with the specified string that cannot be parsed into float64.
+func CantParseFloat64(err error, s string) error {
+ return errors.Wrapf(err, "can't parse %q into float64", s)
+}
+
+// CantParseInt64 wraps the given error with the specified string that cannot be parsed into int64.
+func CantParseInt64(err error, s string) error {
+ return errors.Wrapf(err, "can't parse %q into int64", s)
+}
+
+// CantParseUint64 wraps the given error with the specified string that cannot be parsed into uint64.
+func CantParseUint64(err error, s string) error {
+ return errors.Wrapf(err, "can't parse %q into uint64", s)
+}
+
+// CantPerformQuery wraps the given error with the specified query that cannot be executed.
+func CantPerformQuery(err error, q string) error {
+ return errors.Wrapf(err, "can't perform %q", q)
+}
+
+// CantUnmarshalYAML wraps the given error with the designated value, which cannot be unmarshalled into.
+func CantUnmarshalYAML(err error, v interface{}) error {
+ return errors.Wrapf(err, "can't unmarshal YAML into %T", v)
+}
+
+// MarshalJSON calls json.Marshal and wraps any resulting errors.
+func MarshalJSON(v interface{}) ([]byte, error) {
+ b, err := json.Marshal(v)
+
+ return b, errors.Wrapf(err, "can't marshal JSON from %T", v)
+}
+
+// UnmarshalJSON calls json.Unmarshal and wraps any resulting errors.
+func UnmarshalJSON(data []byte, v interface{}) error {
+ return errors.Wrapf(json.Unmarshal(data, v), "can't unmarshal JSON into %T", v)
+}