From 14219aea59267610a3ca798517bd81ee92245fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 13 Mar 2026 02:11:18 +0100 Subject: [PATCH] fix: return error from Run() when ContinueOnError files fail When --continue-on-error was set and one or more files failed to process, Run() logged each failure but returned nil, making it impossible for callers or CI systems to detect partial failures. Track whether any file failed with a hasErrors flag and return a descriptive error after all files have been attempted. Update TestContinueOnError to reflect the corrected behaviour: the test now asserts that an error IS returned (partial failure is surfaced) while still verifying that all files in the batch are attempted (not just the first one). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- mark.go | 9 +++++++++ markdown/markdown_test.go | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mark.go b/mark.go index 91359c8..927994f 100644 --- a/mark.go +++ b/mark.go @@ -102,6 +102,7 @@ func Run(config Config) error { } } + var hasErrors bool for _, file := range files { log.Infof(nil, "processing %s", file) @@ -109,6 +110,7 @@ func Run(config Config) error { if err != nil { if config.ContinueOnError { log.Errorf(err, "processing %s", file) + hasErrors = true continue } return err @@ -122,6 +124,10 @@ func Run(config Config) error { } } + if hasErrors { + return fmt.Errorf("one or more files failed to process") + } + return nil } @@ -300,6 +306,9 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P if err != nil { return nil, fmt.Errorf("unable to retrieve page by id: %w", err) } + if pg == nil { + return nil, fmt.Errorf("page with id %q not found", config.PageID) + } target = pg } diff --git a/markdown/markdown_test.go b/markdown/markdown_test.go index eb0313e..3f21b7b 100644 --- a/markdown/markdown_test.go +++ b/markdown/markdown_test.go @@ -181,5 +181,8 @@ func TestContinueOnError(t *testing.T) { } err := cmd.Run(context.TODO(), argList) - assert.NoError(t, err, "App should run without errors when continue-on-error is enabled") + // --continue-on-error processes all files even when some fail, but still + // returns an error to allow callers/CI to detect partial failures. + assert.Error(t, err, "App should report partial failure when continue-on-error is enabled and some files fail") + assert.ErrorContains(t, err, "one or more files failed to process") }