A Catch-y iRules Situation
A colleague asked an interesting question late last week about this iRule (simplified to just the primary issue)
when HTTP_REQUEST priority 1 {
if {[
catch {
return
} err
] } {
log local0.error "Error in HTTP_REQUEST: $err" }
}
The question:
When you get a sec- do you know why this iRule will trigger err to log? We're expecting the default return to be graceful and not raise an error code. We notice it logs as a blank error 100% of the time.
The TL;DR is that the catch command, to my understanding until the last few days, returned a 0 for OK or a 1 for ERROR, which aligns well with using an if statement to manage that in an iRule. If Jason had done his RTFM due diligence, he would have known that catch can also return a 2, 3, or 4, which will all lead to a true condition for that if statement, resulting in the undesired log. The simple fix is to be explicit in the if statement by checking for a value of 1.
You can watch the slightly longer version of the explanation here:

Video provider requires cookies to play the video. Accept to continue or watch it directly on the provider's site.