From c0d4ea0d4e0be340e63fb5ac83c0154a0557226f Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Tue, 28 Jul 2026 01:20:41 +0000 Subject: [PATCH] Preserve public error categories from collaborators --- engine_test.go | 26 ++++++++++++++++++++++++++ errors.go | 25 ------------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/engine_test.go b/engine_test.go index 0d95ae1..f2719ec 100644 --- a/engine_test.go +++ b/engine_test.go @@ -915,6 +915,12 @@ func TestArtifactReaderFailuresPreserveArtifactLoadErrors(t *testing.T) { }}, wantNested: context.Canceled, }, + { + name: "public reader error", + ctx: context.Background(), + reader: &recordingArtifactReader{err: scriptorium.ErrInvalidRequest}, + wantNested: scriptorium.ErrInvalidRequest, + }, } for _, tc := range tests { @@ -936,6 +942,26 @@ func TestArtifactReaderFailuresPreserveArtifactLoadErrors(t *testing.T) { } } +func TestRunAddsLLMGenerateToCollaboratorPublicError(t *testing.T) { + engine := newContractEngineWithOptions(t, frameworkSchemaDir, + scriptorium.WithLLMClient(&fakeLLMClient{err: scriptorium.ErrArtifactLoad}), + ) + + _, err := engine.Run(context.Background(), scriptorium.RunRequest{ + PromptID: frameworkMarkdownSummaryPromptID, + Inputs: map[string]scriptorium.ArtifactRef{ + "transcript": scriptorium.Inline("Rin opens the gate."), + "glossary": scriptorium.Inline("gate: A guarded passage."), + }, + }) + if !errors.Is(err, scriptorium.ErrLLMGenerate) { + t.Fatalf("expected ErrLLMGenerate, got %v", err) + } + if !errors.Is(err, scriptorium.ErrArtifactLoad) { + t.Fatalf("expected preserved ErrArtifactLoad, got %v", err) + } +} + func TestPrepareWithoutProfileMatchesSpecificPublicError(t *testing.T) { promptDir := t.TempDir() writePublicPromptFile(t, promptDir, "profile-required", "") diff --git a/errors.go b/errors.go index 4e9ca16..6099b45 100644 --- a/errors.go +++ b/errors.go @@ -13,9 +13,6 @@ func mapPublicError(err error) error { if err == nil { return nil } - if hasPublicError(err) { - return err - } publicErr := publicErrorFor(err) if publicErr == nil { return err @@ -23,28 +20,6 @@ func mapPublicError(err error) error { return fmt.Errorf("%w: %w", publicErr, err) } -func hasPublicError(err error) bool { - for _, publicErr := range []error{ - ErrInvalidConfig, - ErrInvalidRequest, - ErrPromptNotFound, - ErrProfileNotFound, - ErrProfileRequired, - ErrPromptLoad, - ErrProfileLoad, - ErrAPIKeyEnvMissing, - ErrArtifactLoad, - ErrPromptRender, - ErrLLMGenerate, - ErrValidation, - } { - if errors.Is(err, publicErr) { - return true - } - } - return false -} - func publicErrorFor(err error) error { switch { case errors.Is(err, promptdef.ErrPromptDefinitionNotFound):