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>
This commit is contained in:
Manuel Rüger 2026-03-13 02:11:18 +01:00
parent 7d4d0458ca
commit 14219aea59
2 changed files with 13 additions and 1 deletions

View File

@ -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
}

View File

@ -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")
}