summaryrefslogtreecommitdiffstats
path: root/pkg/common/job_error.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/common/job_error.go')
-rw-r--r--pkg/common/job_error.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/common/job_error.go b/pkg/common/job_error.go
new file mode 100644
index 0000000..334c6ca
--- /dev/null
+++ b/pkg/common/job_error.go
@@ -0,0 +1,30 @@
+package common
+
+import (
+ "context"
+)
+
+type jobErrorContextKey string
+
+const jobErrorContextKeyVal = jobErrorContextKey("job.error")
+
+// JobError returns the job error for current context if any
+func JobError(ctx context.Context) error {
+ val := ctx.Value(jobErrorContextKeyVal)
+ if val != nil {
+ if container, ok := val.(map[string]error); ok {
+ return container["error"]
+ }
+ }
+ return nil
+}
+
+func SetJobError(ctx context.Context, err error) {
+ ctx.Value(jobErrorContextKeyVal).(map[string]error)["error"] = err
+}
+
+// WithJobErrorContainer adds a value to the context as a container for an error
+func WithJobErrorContainer(ctx context.Context) context.Context {
+ container := map[string]error{}
+ return context.WithValue(ctx, jobErrorContextKeyVal, container)
+}