From c9f237d9f1e08a75bb865deae6e63f6947a14969 Mon Sep 17 00:00:00 2001 From: Dmitry Sergeev Date: Thu, 27 Aug 2026 00:17:40 +0300 Subject: [PATCH] expose source error classification --- internal/source/errors.go | 4 +++- internal/source/errors_test.go | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/source/errors.go b/internal/source/errors.go index d99e3b4..bdc262c 100644 --- a/internal/source/errors.go +++ b/internal/source/errors.go @@ -31,7 +31,9 @@ func (e *SourceError) Unwrap() error { return e.Err } -func errorKind(err error) ErrorKind { +// KindOf returns the source error category contained in err. +// It returns ErrorKindUnknown when err has no SourceError in its chain. +func KindOf(err error) ErrorKind { var sourceErr *SourceError if errors.As(err, &sourceErr) { return sourceErr.Kind diff --git a/internal/source/errors_test.go b/internal/source/errors_test.go index bb6178f..a025178 100644 --- a/internal/source/errors_test.go +++ b/internal/source/errors_test.go @@ -6,12 +6,12 @@ import ( "testing" ) -func TestErrorKindThroughWrapping(t *testing.T) { +func TestKindOfThroughWrapping(t *testing.T) { base := errors.New("producer disappeared") wrapped := wrapError("read video", ErrorKindUnavailable, base) outer := fmt.Errorf("worker failed: %w", wrapped) - if got := errorKind(outer); got != ErrorKindUnavailable { + if got := KindOf(outer); got != ErrorKindUnavailable { t.Fatalf("errorKind() = %v, want %v", got, ErrorKindUnavailable) } if !errors.Is(outer, base) { @@ -22,8 +22,8 @@ func TestErrorKindThroughWrapping(t *testing.T) { } } -func TestErrorKindUnknown(t *testing.T) { - if got := errorKind(errors.New("ordinary error")); got != ErrorKindUnknown { +func TestKindOfUnknown(t *testing.T) { + if got := KindOf(errors.New("ordinary error")); got != ErrorKindUnknown { t.Fatalf("errorKind() = %v, want %v", got, ErrorKindUnknown) } }