Skip to content

postprocess: Add --on-error flag for non-fatal transform failures#1851

Merged
Crocodoctopus merged 1 commit into
masterfrom
bg/postprocess-skip-comment-mismatch
Jun 13, 2026
Merged

postprocess: Add --on-error flag for non-fatal transform failures#1851
Crocodoctopus merged 1 commit into
masterfrom
bg/postprocess-skip-comment-mismatch

Conversation

@Crocodoctopus

@Crocodoctopus Crocodoctopus commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Adds configurable transform error handling via --on-error.

Comment transform failures now raise TransformError instead of relying on a hard assert. The CLI can either abort on the first failure, keep going while returning exit 1, or warn and return exit 0.

As part of this, cache.update(...) now happens only after the comment parity check succeeds.

@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch from c25423c to 8d5b23a Compare June 11, 2026 22:24

@thedataking thedataking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right now, the postprocessor only transfers comments but we have PRs to process assertions, and other useful cleanup. I don't think we should have a comment-specific flag.

Please consider a more generic design where we accept a flag (or flag pair --fail-fast/--no-fail-fast with the former being the default) that any Transform that derives from AbstractTransform can use to decide whether to keep going or not.

@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch 4 times, most recently from 9797c41 to a70460a Compare June 11, 2026 23:52
@Crocodoctopus Crocodoctopus changed the title postprocess: Add option to skip comment mismatches postprocess: Add continue-on-error flag for non-fatal transform failures Jun 11, 2026
@Crocodoctopus

Copy link
Copy Markdown
Contributor Author

The flag ended up being --continue-on-error, which is now passed to AbstractTransform for future transforms.

@thedataking

Copy link
Copy Markdown
Contributor

The flag ended up being --continue-on-error, which is now passed to AbstractTransform for future transforms.

cargo test supports --keep-going which is what you initially proposed.
I mentioned --fail-fast, --no-fail-fast because cargo nextest exposes that.
Why did you chose --continue-on-error? Considering all the options, I think your --keep-going suggestion is best since (I assume) more people use and know about the cargo test CLI than the cargo nextest one.

Comment thread c2rust-postprocess/postprocess/__init__.py Outdated
Comment thread c2rust-postprocess/postprocess/transforms/comments.py Outdated
@thedataking

Copy link
Copy Markdown
Contributor

from offline discussion: --keep-going or --no-fail-fast isn't exactly what we need here since we also want to option to downgrade errors to warnings so postprocessing can run in best effort mode. Simplest solution that covers CI, development, and CRISP use requirements:

Tri-state on-error {abort, keep-going, warn} flag. With the following semantics:

  • abort: stop at first failure, nonzero exit (development/debugging)
  • keep-going: process everything, report all failures, nonzero exit (CI)
  • warn: process everything, log failures as warnings, exit 0 (embedding in a larger tool)

keep-going is the safe default for users of c2rust.

We can use exceptions to simplify error handling:

  class TransformError(Exception): ...

  if c_comments != rust_comments:
      raise TransformError(f"comment mismatch for {identifier}: {c_comments=} {rust_comments=}")

Then the policy logic goes here:

  1. The per-function loop in apply_file (base.py:108) wraps the apply_ident call in try/except TransformError; on abort it re-raises, otherwise it records the failure and
    continues.
  2. main() looks at the collected failure count at the end: nonzero exit unless mode is warn (where it logs a summary like "postprocessed N functions, skipped M due to errors" and returns 0).

For PR #1849 specifically (not blocking for this PR) :
One complication is that we might want to always keep going if TrimTransform fails but the on-error flag is flexible enough to allow more states if we absolutely need them.

@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch 2 times, most recently from cd1862c to efb8cba Compare June 12, 2026 03:53
@thedataking thedataking changed the title postprocess: Add continue-on-error flag for non-fatal transform failures postprocess: Add --on-error flag for non-fatal transform failures Jun 12, 2026
@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch from efb8cba to 51ac43a Compare June 12, 2026 05:22
@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch from 51ac43a to 05f1224 Compare June 12, 2026 06:35
Comment thread c2rust-postprocess/postprocess/__init__.py Outdated
Comment thread c2rust-postprocess/postprocess/transforms/__init__.py Outdated

@thedataking thedataking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR body is stale. Cache.update was moved to after the comment-verbatim check. Worth doing but you should document the change when you update the PR body.

continue_on_error appears to be a vestige from previous iteration; remove it?

@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch 2 times, most recently from 20a26d7 to ee47bc7 Compare June 12, 2026 19:15
@Crocodoctopus

Crocodoctopus commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I was unaware the top-most comment should be edited to reflect the current state of the PR, I'll do that from now on.

Instances of the old continue_on_error were all removed.

This should be g2g?

@thedataking thedataking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with one nitpick:

Please undo formatting changes in transforms/init.py and comments.py.

  • transforms/__init__.py changes can just be removed from this commit entirely
  • comments.py: just need to revert CommentsTransform.__init__

(logging.exception works well here, nice find. note that it prints the error at the end of the traceback as well as in the f-string you pass as an argument - should be harmless.)

@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch from ee47bc7 to 11f9c7f Compare June 12, 2026 23:24
Add an --on-error option for per-function transform failures.

The default keep-going mode continues after TransformError failures and
exits nonzero if any function failed. abort stops at the first
TransformError. warn continues after TransformError failures, reports
them as warnings, and exits successfully.

Only TransformError is treated as a recoverable per-function failure;
other exceptions still surface as normal program errors.
@Crocodoctopus Crocodoctopus force-pushed the bg/postprocess-skip-comment-mismatch branch from 11f9c7f to 516ffa0 Compare June 12, 2026 23:38
@Crocodoctopus Crocodoctopus merged commit 2084ff6 into master Jun 13, 2026
11 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.

2 participants