Kentzo
August 26, 2026, 12:39am
1
In my scripts I relied on /file/set to trigger an error when executed inside :onerror block, like so:
:onerror varError in={
/file/set $argPath contents=$argContents
} do={
:if ($varError ~ "no such item") do={
/file/add name=$argPath type=file contents=$argContents
} else={
:error $varError
}
}
But I just noticed that on 7.21.5 it doesn't trigger the error anymore, not even logging one. Just quietly fails. Was I hallucinating when I wrote it? Or is it a bug that was fixed in newer versions of RouterOS?
Kentzo
August 26, 2026, 12:49am
2
In the meantime modified it by adding /file/get which still triggers the error:
:onerror varError in={
/file/get $argPath value-name=size
/file/set $argPath contents=$argContents
} do={
:if ($varError ~ "no such item") do={
/file/add name=$argPath type=file contents=$argContents
} else={
:error $varError
}
}
Amm0
August 26, 2026, 1:46am
3
Both versions work on 7.24.0 in a quick test. But I tried on long-term using same code, and it does not work. Now I did the following at CLI on both.
{
:local argPath disk1/kfile1
:local argContents kfile1
:onerror varError in={
/file/set $argPath contents=$argContents
} do={
:if ($varError ~ "no such item") do={
/file/add name=$argPath type=file contents=$argContents
} else={
:put "in error block"
:error $varError
}
}
:put [/file/get $argPath contents]
}
So 7.21.5 get "no such item" (seemingly skipping your check, since I do not see the "in error block" message. While 7.24.0, works as expected.