Skip to content

firewall: return graceful failure instead of 500 on rule not-found - #10430

Open
haxorton wants to merge 1 commit into
opnsense:masterfrom
haxorton:fix/firewall-move-toggle-500
Open

firewall: return graceful failure instead of 500 on rule not-found#10430
haxorton wants to merge 1 commit into
opnsense:masterfrom
haxorton:fix/firewall-move-toggle-500

Conversation

@haxorton

Copy link
Copy Markdown
Contributor

Important notices

Before you submit a pull request, we ask you kindly to acknowledge the following:

If AI was used, please disclose:

  • Model used: Opus 4.8
  • Extent of AI involvement: testing, surfacing the code location and writing a nice commit message

Describe the problem

moveRuleBefore (FilterController and FilterBaseController::moveRuleBeforeBase) and toggleRuleLogBase threw a UserException when the referenced rule uuid did not exist.

Because api.php renders every thrown exception as HTTP 500, a non-existent uuid produced a 500, whereas the inherited del/set/toggle verbs return {"result":"failed"} and these very methods already return ["status" => "error", ...] for an invalid request method.


Describe the proposed solution

Return that same ["status" => "error", ...] shape for the not-found case so the outcome is consistent and no longer surfaces as a server error

Again, not something breaking but more a OCD topic to make it more streamlined.


Related issue

None found

moveRuleBefore (FilterController and FilterBaseController::moveRuleBeforeBase) and toggleRuleLogBase threw a UserException when the referenced rule uuid did not exist.

Because api.php renders every thrown exception as HTTP 500, a non-existent uuid produced a 500, whereas the inherited del/set/toggle verbs return {"result":"failed"} and these very methods already return ["status" => "error", ...] for an invalid request method.

Return that same ["status" => "error", ...] shape for the not-found case so the outcome is consistent and no longer surfaces as a server error
@fichtner

Copy link
Copy Markdown
Member

I'm not sure this is the way to go here. We were planning to increase the use of UserException() because it works on all GUI pages. Deferring to @AdSchellevis when he is back.

@haxorton

Copy link
Copy Markdown
Contributor Author

Ah if that is the plan, then I am fine with that too :)

@AdSchellevis

Copy link
Copy Markdown
Member

The user exceptions are intentional indeed, but we might need to improve the error model a bit for consistency indeed. Let's keep this open for further discussion.

A lot of these standard errors are silently ignored, which in most cases isn't an issue as these are hardly triggered anyway. We could consider adding some different exceptions and trapping them in the UI like the user-exception at some point for clarity.

@haxorton

Copy link
Copy Markdown
Contributor Author

Anything I can support with? I really like opnsense and love to have it, so when I can do something please say so.

@AdSchellevis

Copy link
Copy Markdown
Member

@haxorton not yet, but thanks for the offer.

@AdSchellevis

Copy link
Copy Markdown
Member

added 99e49c5 to offer some typing for exceptions and replaced the ones in the firewall code with warnings. For consistency we might consider replacing some other callers as well.

@AdSchellevis AdSchellevis reopened this Jul 22, 2026
fichtner pushed a commit that referenced this pull request Aug 12, 2026
…ase template

PR: #10430

Although we can debate about the http status codes (kept the standard one at 500,  warning and info as 200), the idea is to add some glue for the frontend so it knows what we mean and can represent the dialog based on its type.

(cherry picked from commit 99e49c5)
(cherry picked from commit 5023639)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants