Skip to content

Commit

Permalink
report error to human
Browse files Browse the repository at this point in the history
  • Loading branch information
eightnoteight committed Feb 6, 2024
1 parent fa32e1f commit bd1895e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions report.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package errors

import (
"context"
"fmt"
"os"

"log/slog"
)

var reportErrorToHuman bool = os.Getenv("REPORT_ERROR_TO_HUMAN") == "true"

type Severity string

func (s Severity) String() string {
Expand All @@ -31,6 +35,10 @@ func ReportWithSeverity(ctx context.Context, err error, severity Severity) {
ctx, "error: "+err.Error(),
SlogErr(err), slog.String("severity", severity.String()),
)

if reportErrorToHuman {
fmt.Printf("error: %s\nseverity: %s\n%+v\n", err.Error(), severity.String(), err)
}
}

func Report(ctx context.Context, err error) {
Expand Down

0 comments on commit bd1895e

Please sign in to comment.