Skip to content

fs: add --max-errors flag - fixes #4670 - #10271

Merged
ncw merged 2 commits into
rclone:masterfrom
hsdfat:fs-max-errors-4670
Nov 25, 2026
Merged

ncw merged 2 commits into
rclone:masterfrom
hsdfat:fs-max-errors-4670

Conversation

@hsdfat

@hsdfat hsdfat commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

What does this change do?

Adds a global --max-errors N flag that stops rclone transferring once N errors have been counted, as suggested in #4670: it sits next to --max-transfer and --max-duration and honours --cutoff-mode.

  • HARD (default): the next transfer that would start returns a fatal error, so sync cancels and no retries are attempted.
  • SOFT / CAUTIOUS: no new transfers are started, transfers already in progress finish (same path as --max-transfer with SOFT).
  • Errors from earlier --retries attempts count too. StatsInfo gets a totalErrors counter that ResetErrors() (called between retries) leaves alone, and cmd.Run stops retrying once the limit is reached.

The check is in (*copy).checkLimits, so it gates the start of each transfer. It does not interrupt a transfer mid-read, and deletes/checks in sync are not gated. The docs say "no new transfers will be started".

I didn't add a dedicated exit code: HARD exits 7 (fatal error) and SOFT exits 9 (no-retry error). Happy to add one alongside 8 (--max-transfer) and 10 (--max-duration) if you'd like.

Tests: TestStatsTotalErrors (count survives ResetErrors), TestCopyFileMaxErrors (fatal vs graceful error per cutoff mode) and TestMaxErrors/{Hard,Soft,Cautious} in fs/sync. I also ran it end to end with unreadable source files and --retries 3.

Linked issue

Fixes #4670

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

Add --max-errors N to stop transferring once N errors have been
counted. Errors from previous --retries attempts are included.

With --cutoff-mode hard (the default) rclone stops with a fatal
error. With soft (and cautious) no new transfers are started and
running transfers are allowed to finish. No further retries are
attempted once the limit is reached.
@hsdfat
hsdfat requested review from ncw and nielash as code owners November 6, 2026 12:13

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for doing this - it looks very nice :-)

I think there is one thing missing.

In cmd/cmd.go can you adjust resolveExitCode for consistency with --max-transfer (8) and --max-duration (10) so that --max-errors has a dedicated exit code? And adjust the docs accordingly.

Thanks

@hsdfat

hsdfat commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Done in 8f8e26d.

--max-errors now has exit code 11 (exitcode.ErrorsExceeded), and the docs list it next to 8 and 10.

resolveExitCode returns 11 when the error is ErrorMaxErrorsReached or when the error count has reached the limit. I added the second check because with --cutoff-mode SOFT the last error is one of the transfer errors, not the limit error, so matching the error alone gave exit code 1.

I checked the built binary by copying a directory with unreadable files: --max-errors 2 exits with 11 in both HARD and SOFT mode, a limit that is not reached still exits with 1, and a clean copy exits with 0.

I pushed this as a second commit so the change is easy to see. I can squash it if you prefer.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you - this looks great :-)

@ncw
ncw merged commit 5417c54 into rclone:master Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to abort after N errors

2 participants