[high] Re-apply #98: exit non-zero and keep converting when a rule fails with --output-dir (reverted with #105) - #110
Open
elhoim wants to merge 1 commit into
Conversation
Re-applies SigmaHQ#98, which was merged but then undone on main: the merge of SigmaHQ#105 (8effb4c) brought in cdd5436, a revert of a conflict-resolution merge (86d3041) that had carried SigmaHQ#98 and SigmaHQ#99 into the SigmaHQ#105 branch. Adapted to SigmaHQ#105's write_separate_files(): rules are converted one by one without a callback, so a failing rule is reported and counted instead of aborting the conversion of every later rule behind a warning. Each successful conversion stores its finalized result on the rule, which SigmaHQ#105 then collects via get_output_rules()/get_conversion_result(). The command exits 1 when any rule failed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLUF
--output-dir"). It was merged, but the revertcdd5436that came in with [high] Write finalized, postprocessed queries with --output-dir #105 (merge8effb4c) silently removed it frommain.--output-dir, the first rule that fails to convert aborts the conversion of every later rule, only a warning is printed, and the command exits 0 - a CI job reports success with an incomplete or empty output directory.write_separate_files()to write finalized, postprocessed queries. This keeps that design and only replaces its singletry: backend.convert(...) except Exception: warnwith a per-rule loop (asBackend.convertdoes, without a callback). Each successful conversion stores its finalized result on the rule, which [high] Write finalized, postprocessed queries with --output-dir #105'sget_output_rules()/get_conversion_result()collection then writes. Failing rules are reported and the command exits 1 when any failed.stderrassertions) are back; the main one fails on currentmainand passes here. All of [high] Write finalized, postprocessed queries with --output-dir #105's tests still pass, includingtest_convert_output_dir_basic, the test the reverted resolution broke. Full suite with thepoetry.lockpins (pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2, Python 3.12): 123 passed, 1 skipped.Priority: high
What happened
mainno longer contains #98, although it was merged:47712d0) and [high] Exit non-zero and keep converting when a rule fails with --output-dir #98 (c8348d7) were merged on 2026-09-27 before [high] Write finalized, postprocessed queries with --output-dir #105.main. The resolution86d3041("Merge github/main: resolve conflicts in convert.py and test_convert.py") brought [high] Exit non-zero and keep converting when a rule fails with --output-dir #98 and [high] Report collection errors and broken filters in sigma check #99 into the [high] Write finalized, postprocessed queries with --output-dir #105 branch, but it failstests/test_convert.py::test_convert_output_dir_basic(reproduced locally).cdd5436("Revert "Merge github/main: ...""), and [high] Write finalized, postprocessed queries with --output-dir #105 was merged with that revert (8effb4c). The revert removed the whole mergedmainside from the branch, so merging [high] Write finalized, postprocessed queries with --output-dir #105 took [high] Exit non-zero and keep converting when a rule fails with --output-dir #98's and [high] Report collection errors and broken filters in sigma check #99's changes back out ofmain:8effb4cdeletes the 22 lines [high] Report collection errors and broken filters in sigma check #99 added tosigma/cli/check.pyand its 51 lines of tests, and restores the old--output-direrror handling.Probably nobody intended to revert #98 and #99; they were collateral of undoing a broken conflict resolution.
Original description (#98)
BLUF
--output-dir, any conversion error is downgraded to a warning and the command exits 0. Every rule after the failing one is silently dropped.sigma convert -t <backend> -od out/ rules/in a CI job reports success whileout/is incomplete, and can even be empty. The same input without-odexits 1.write_separate_files(), report each failing rule, keep writing the others, and exit 1 when any rule failed.mainand passes with the fix. The second guards--skip-unsupported(still exit 0, reported under "Ignored errors").Priority: high
Details
Root cause:
sigma/cli/convert.py:192-195Backend.convert()is a single list comprehension over all rules. The first exception aborts it, so the callback never runs for later rules. The exception is then swallowed. The single-output path (convert.py:590-601) turns the sameSigmaError/NotImplementedErrorintoError while converting: ...with exit status 1.The fix does what
Backend.convert()does:init_processing_pipeline()andresolve_rule_references(), thenconvert_rule()/convert_correlation_rule()in collection order with the existing callback. The difference is thatSigmaError/NotImplementedErroris caught per rule.finalize()is not called, but the old code discarded its return value anyway. After the files are written, aClickExceptionreports the number of failed rules.-s/--skip-unsupportedstill works as before. In that mode the backend collectsSigmaErrors itself (collect_errors=True), and they are listed under "Ignored errors" with exit 0.Before (rule
a.ymluses an unresolvable|expandplaceholder,b.ymlis fine):After:
This PR is independent of the other
--output-dirPR, which changes the write loop of the same function. Whichever lands second, I'll rebase it.Testing
test_convert_output_dir_conversion_error_fails_and_continues(fails onmain, passes here) andtest_convert_output_dir_conversion_error_skip_unsupported.poetry.lock: pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2):pytest --cov=sigma→ 120 passed, 1 skipped.🤖 Generated with Claude Code