Rust: limit number of diagnostics to 100 per trap file#19774
Merged
Conversation
bd214b4 to
c960af8
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a hard cap of 100 diagnostics per trap file to prevent excessive emissions.
- Introduced an
emit_diagnostic_limitfield onTranslatorand initialized it to 100. - Added
EMIT_DIAGNOSTIC_LIMIT_PER_FILEconstant and applied a check/decrement in the diagnostic emission path. - Kept existing behavior for
Debug-level diagnostics (they are not counted against the limit).
Comments suppressed due to low confidence (2)
rust/extractor/src/translate/base.rs:126
- Add a doc comment for the
emit_diagnostic_limitfield (and forEMIT_DIAGNOSTIC_LIMIT_PER_FILE) to explain its purpose and units, so future maintainers understand its role.
emit_diagnostic_limit: usize,
rust/extractor/src/translate/base.rs:251
- No tests were added to verify that diagnostics stop after the limit is reached; consider adding a unit or integration test that emits over 100 diagnostics and asserts that subsequent ones are suppressed.
if severity > DiagnosticSeverity::Debug && self.emit_diagnostic_limit > 0 {
rust/extractor/src/translate/base.rs
Outdated
| const UNKNOWN_LOCATION: (LineCol, LineCol) = | ||
| (LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 }); | ||
|
|
||
| const EMIT_DIAGNOSTIC_LIMIT_PER_FILE: usize = 100; |
There was a problem hiding this comment.
[nitpick] Consider making the diagnostic limit configurable (e.g., via a constructor argument or config file) instead of a fixed constant, which would improve flexibility and allow per-project adjustments.
hvitved
previously approved these changes
Jun 18, 2025
fdc2be8 to
05ab438
Compare
05ab438 to
a253b31
Compare
redsun82
approved these changes
Jun 20, 2025
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.
This pull request limits the number of error/warning/info diagnostics we store in the CodeQL database to 100 per file. This should avoid SARIF from growing too large.