demo(13-throw-bare-exception): 13 — New throw new Exception(...) path with no test coverage#148
demo(13-throw-bare-exception): 13 — New throw new Exception(...) path with no test coverage#148
throw new Exception(...) path with no test coverage#148Conversation
There was a problem hiding this comment.
GauntletCI found the following issues:
These findings reference lines outside the PR diff, so they appear here instead of inline. Expand each entry for full evidence, rationale, and suggested action.
GCI0032 — Uncaught Exception Path: 1 'throw new' statement(s) added without Assert.Throws or Should().Throw evidence in this diff.
GCI0032 — Uncaught Exception Path
1 'throw new' statement(s) added without Assert.Throws or Should().Throw evidence in this diff.
Evidence:
1 added 'throw new' statement(s) in non-test files.
💡 Suggested action: Add xUnit Assert.Throws<T> or FluentAssertions .Should().Throw<T>() tests for each new exception path.
Confidence: Medium | Severity: Block
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6af783686
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { | ||
| if (amount.Amount < 0m) | ||
| { | ||
| throw new Exception($"Amount must be non-negative: {amount.Amount}"); |
There was a problem hiding this comment.
Throw a specific exception for invalid money amounts
When RequireNonNegative receives a negative value, it throws System.Exception, which makes this validation failure indistinguishable from unexpected faults for callers and tests that handle argument errors by type. For input validation paths like this, use a typed exception (for example ArgumentOutOfRangeException) so downstream code can reliably catch and react to this condition.
Useful? React with 👍 / 👎.
…th with no test coverage See scenarios/13-throw-bare-exception/README.md for the expected verdict.
|
Reopening with refreshed scenario. |
a6af783 to
c139c98
Compare
13 — New
throw new Exception(...)path with no test coverageExpected verdict: ❌ Fails — GauntletCI should fire GCI0032 (uncaught exception path).
What changed
PricingServicegains a new validation helper that throws a bareSystem.Exceptionwhen an amount is negative:The diff adds a
throw newin production code without adding anycorresponding
Assert.Throws<>/Should().Throw<>()test in thetest project.
Why this is risky
throw new Exception(...)is the wrong base type. Callers cannotcatchsomething more specific without also catching every otherbug. The .NET guidelines explicitly call this out.
has ever executed. The first time it fires will be in production.
ArgumentOutOfRangeException(which has dedicated handling everywhere in .NET) and (b) add an
Assert.Throws<ArgumentOutOfRangeException>(...)test.What GauntletCI catches
GCI0032 Uncaught Exception Path— one or morethrow newstatementsin non-test files in the diff, with no corresponding throw-assertion
(
Assert.Throws,Should().Throw,ThrowsAsync,Throws<…>) in anytest file in the same diff.