diff --git a/pkg/stacktrace/main.go b/pkg/stacktrace/main.go index 471c709..98237cb 100644 --- a/pkg/stacktrace/main.go +++ b/pkg/stacktrace/main.go @@ -3,9 +3,12 @@ package stacktrace import ( "fmt" "git.codebau.dev/goblins/commons/pkg/osdep" + "math" "runtime" ) +const NoStatusCode = math.MinInt + type ErrorReporter struct { EnableStacktraces bool } @@ -18,7 +21,8 @@ type StackElement struct { type ErrorWithStacktrace struct { error - Stack *[]*StackElement + ErrorCode int + Stack *[]*StackElement } func (s *ErrorWithStacktrace) build(enableStackTraces bool) { @@ -65,7 +69,13 @@ func (s *ErrorWithStacktrace) Stacktrace() *[]*StackElement { } func (r *ErrorReporter) New(err error) *ErrorWithStacktrace { - s := &ErrorWithStacktrace{error: err} + s := &ErrorWithStacktrace{error: err, ErrorCode: NoStatusCode} + s.build(r.EnableStacktraces) + return s +} + +func (r *ErrorReporter) NewWithErrorCode(errorCode int, err error) *ErrorWithStacktrace { + s := &ErrorWithStacktrace{error: err, ErrorCode: errorCode} s.build(r.EnableStacktraces) return s }