Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 21068

Scripting • Re: Possible bugs with :onerror (new in 7.13)

$
0
0
I guess I'm not sure what you think is wrong. Getting the error text is main point of :onerror – so on the right track for adding prefix to logging text.

First understand only the in= block runs if there is NO error (either explicit :error, or RouterOS generated one). The "do=" block only run IF some error occurred. The following code works as expected, the local variables IN SAME SCOPE are available:
Code:
{ :local prefix "vardata"; :onerror err in={:error "errortest"} do={:put "$prefix $err"} }# vardata errortest

But in general you can avoid most error conditions by using ":if" to AVOID error conditions in the first place – which is generally a better approach. If you do this, you can write whatever you want to log if your code since you check for bad values/etc BEFORE an error is generated.

Totally get that's not always possible... and where :onerror might be useful. But I'm not sure it good idea MORE work other than logging in the do= of :onerror... Perhaps wrapping your ENTIRE script in the in= block, and the do= block of the main :onerror does your needed logging and exits after is a better approach THAN using MULTIPLE onerror blocks throughout a script.

Statistics: Posted by Amm0 — Tue Jan 09, 2024 5:56 pm



Viewing all articles
Browse latest Browse all 21068

Trending Articles