Community discussions

MikroTik App
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 2:27 pm

Hi all,

I’m hitting a challenging bug or behavior where running a script provokes a prompt for "value:" instead of completing. This only happens with certain scripts. I can’t figure out why.

Here are a few code samples to illustrate, which can be run from the Terminal in webfig to provoke the behavior. I have posted "working" (versions that complete normally) and "not working" (versions that go to "value:" prompt). I can therefore reproduce it in a few ways but I can't discern any logic or way to counter it.

I am completely dead in the water on my project due to this. I cannot figure out any reliable way to work around it.

Have you experienced this before? Is it a known bug? Is there some rational way around it? How can I make my code work?

I posted the script I am trying to make work at the bottom to illustrate. I have spent 5-8+ hours now with ChatGPT and Grok trying to figure this out, and I am no further ahead.

Thanks for any help. (/system resource print = version: 7.15.2 (stable))

Set up Temp Script

You can run this line to set up the temp script, then just copy and paste any code block below in after to run them.
/system script add name=cloudflare_ddns policy=read,write,test source=""

EXAMPLE 1

==============
DOESN'T WORK
==============

/system script set cloudflare_ddns source={
:local ipCheckURL "http://api.ipify.org";
:local currentIP;

:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
    :return;
} on-error={
    :log warning "Fetch failed";
    :return;
};

:local noop "done"
};
/system script run cloudflare_ddns; 
==============
WORKS
==============

/system script set cloudflare_ddns source={
:local result;
:do {
    :set result [/tool fetch url="http://api.ipify.org" output=user as-value];
} on-error={
    :log warning "fail";
};

:local noop "done"
};
/system script run cloudflare_ddns; 

EXAMPLE 2

================================
DOESN'T WORK:
================================

/system script set cloudflare_ddns source={
:local cfSubdomain "www";
:local cfZoneName "google.com";

:local cfDomain ($cfSubdomain . "." . $cfZoneName);
:local ipCheckURL "http://api.ipify.org";
:local currentIP;

:local unused [:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
} on-error={
    :log warning "Cloudflare DDNS: Failed to fetch public IP from $ipCheckURL - skipping update.";
}];

:if ($currentIP = "") do={
    :log warning "Cloudflare DDNS: Empty response from IP check - skipping update.";
    :return;
};

:local newIP ($currentIP->"data");
:set newIP [:pick $newIP 0 [:find $newIP "\n" -1]];
:local ipParsed [:toip $newIP];
:local ipLength [:len $ipParsed];

:if ($ipLength = 0) do={
    :log warning "Cloudflare DDNS: Invalid IP detected: $newIP - skipping update.";
    :return;
};
};

/system script run cloudflare_ddns; 

================================
WORKS:
================================

/system script set cloudflare_ddns source={
:local cfSubdomain "www";
:local cfZoneName "google.com";

:local cfDomain ($cfSubdomain . "." . $cfZoneName);
:local ipCheckURL "http://api.ipify.org";
:local currentIP;

:local unused [:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
} on-error={
    :log warning "Cloudflare DDNS: Failed to fetch public IP from $ipCheckURL - skipping update.";
}];

:if ($currentIP = "") do={
    :log warning "Cloudflare DDNS: Empty response from IP check - skipping update.";
    :return;
};

:local newIP ($currentIP->"data");
:set newIP [:pick $newIP 0 [:find $newIP "\n" -1]];
:local ipParsed [:toip $newIP];
:local ipLength [:len $ipParsed];
};
/system script run cloudflare_ddns; 

REAL CODE I AM TRYING TO MAKE WORK

For reference, this is what I'm trying to do - a script to update cloudflare DNS from the public dynamic IP. I think it should be simple enough but I can't get past this behavior. Thanks again for any help.
/system script set cloudflare_ddns source={
:local cfSubdomain "subdomain";
:local cfZoneName "domain.com";
:local cfZoneID "zoneid";
:local cfToken "token";

:local cfDomain ($cfSubdomain . "." . $cfZoneName);
:local ipCheckURL "http://api.ipify.org";
:local currentIP;

:local unused [:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
} on-error={
    :log warning "Cloudflare DDNS: Failed to fetch public IP from $ipCheckURL - skipping update.";
}];

:if ($currentIP = "") do={
    :log warning "Cloudflare DDNS: Empty response from IP check - skipping update.";
    :return;
};

:local newIP ($currentIP->"data");
:set newIP [:pick $newIP 0 [:find $newIP "\n" -1]];
:local ipParsed [:toip $newIP];
:local ipLength [:len $ipParsed];

:if ("$ipLength" = 0) do={
    :log warning "Cloudflare DDNS: Invalid IP detected: $newIP - skipping update.";
    :return;
};

:local apiURL "https://api.cloudflare.com/client/v4/zones/$cfZoneID/dns_records?type=A&name=$cfDomain";
:local result;
:local headerField ("Authorization: Bearer $cfToken, Content-Type: application/json");

:local unused [:do {
    :set result [/tool fetch url=$apiURL http-method=get output=user http-header-field=$headerField check-certificate=yes as-value];
} on-error={
    :log warning "Cloudflare DDNS: Failed to reach Cloudflare API for lookup - skipping update.";
}];

:if ($result = "") do={
    :log warning "Cloudflare DDNS: Empty response from API lookup - skipping update.";
    :return;
};

:local response ($result->"data");

:if ([:len $response] = 0) do={
    :log info "Cloudflare DDNS: No A record for $cfDomain - creating new one...";
    :local postData ("{\"type\":\"A\",\"name\":\"" . $cfDomain . "\",\"content\":\"" . $newIP . "\",\"ttl\":120,\"proxied\":false}");
    :local unused [:do {
        /tool fetch url="https://api.cloudflare.com/client/v4/zones/$cfZoneID/dns_records" http-method=post http-header-field=$headerField http-data=$postData check-certificate=yes output=none;
        :log info "Cloudflare DDNS: DNS record created successfully.";
    } on-error={
        :log warning "Cloudflare DDNS: Failed to create DNS record.";
    }];
    :return;
};

:local cfRecord [:pick $response 0];
:local recordID ($cfRecord->"id");
:local oldIP ($cfRecord->"content");

:if ($newIP != $oldIP) do={
    :log info "Cloudflare DDNS: IP changed from $oldIP to $newIP - updating...";
    :local putData ("{\"type\":\"A\",\"name\":\"" . $cfDomain . "\",\"content\":\"" . $newIP . "\",\"ttl\":120,\"proxied\":false}");
    :local unused [:do {
        /tool fetch url="https://api.cloudflare.com/client/v4/zones/$cfZoneID/dns_records/$recordID" http-method=put http-header-field=$headerField http-data=$putData check-certificate=yes output=none;
        :log info "Cloudflare DDNS: DNS record updated successfully.";
    } on-error={
        :log warning "Cloudflare DDNS: Failed to update DNS record.";
    }];
} else={
    :log info "Cloudflare DDNS: IP unchanged ($newIP), no update needed.";
};
};
/system script run cloudflare_ddns; 
Last edited by jonjm on Thu Apr 10, 2025 11:55 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12980
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 4:30 pm

RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?
Original title, for future reference

Why did you write RouterOS BUG???
Before writing something like that, wouldn't it be better to first ask for advice on the bugs you have?

Do you like large fonts?

Artificial deficiency and other frills greatly diminish intellectual capacity.

What does ":return" mean, a meaningless thing thrown in there?

Don't you have the slightest ability to notice that the real difference between the first two scripts is the completely useless and ridiculous presence of ":return"???

Whatever AI you used, it can't fill your gaps, and neither can your intuition.
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 5:26 pm

IMO point is here to exit script without producing error and avoid deep condition nesting (guard conditions)... As I recall :return <sometning> did not produce error (or just script error wasn't logged) up to some 7.x version when called outside function, but now does.
Simple workaround without changing much is to put whole script into some function and calling that function, eg. :local main do={<script_code>}; $main and calling :return [:noting] (error in OP code that :return is missing argument) inside that function will not produce error.

And OFC code like this doesn't make any sense :) (never to pass after this command):
:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
    :return;
} on-error={
    :log warning "Fetch failed";
    :return;
};
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 8:34 pm

IMO point is here to exit script without producing error and avoid deep condition nesting (guard conditions)... As I recall :return <sometning> did not produce error (or just script error wasn't logged) up to some 7.x version when called outside function, but now does.
Simple workaround without changing much is to put whole script into some function and calling that function, eg. :local main do={<script_code>}; $main and calling :return [:noting] (error in OP code that :return is missing argument) inside that function will not produce error.


Thank you for your reply! Yes, the examples were of course experiments I had been doing or simplified cases to try to figure out what the problem was (I tried dozens of code examples to try to figure it out). The exact logic in the examples wasn't important, I was just experimenting to narrow it down.

I understand the problem now. I did a bit more testing based on your reply. I did not see it last night.

The solution in all code examples seems to be you must return SOMETHING. You cannot simply ":return", so just return nonsense if needed eg. ":return 1".

EXAMPLE 1 SOLUTION

- Issue: Must return something always even if dummy value and trying to break function early.
/system script set cloudflare_ddns source={
:local ipCheckURL "http://api.ipify.org";
:local currentIP;

:do {
    :set currentIP [/tool fetch url=$ipCheckURL output=user as-value];
    :return 1;
} on-error={
    :log warning "Fetch failed";
    :return 1;
};
}
/system script run cloudflare_ddns; 
This now runs without prompting "value:"

It appears to be the same issue in the second example and my real script too. When I replace "return" with "return 1" the "value:" prompt and hang goes away.

Conclusion

ChatGPT 4o states currently about return in RouterOS:
- If you use the :return command without a value, it returns nothing. This is similar in behavior to a null return in some contexts
- If you use :return someValue, it returns that value.
- There is no built-in null keyword in RouterOS scripting.
However, this seems to be wrong. If we return without a value, this is how we get to the "value:" prompt and the code hangs. So I will presume that is the case. This is easy to work around then. We must just always return some value even if it is meaningless to our system when doing early return.

Conclusion:

Not a bug, just a language constraint - ":return" must return something (1, 0, "", anything). No "null" or "empty" :return allowed.

My main script is now running at least confirmed in logs with this fix, so I can proceed further with it then.

Documentation:

There are only three examples of ":return" in the Mikrotik documentation here where it states: "Starting from v6.2 new syntax is added to easier define such functions and even pass parameters. It is also possible to return function value with :return command." They give as an example ":global funcA do={ :return 5 } ". I note all examples they give all return a value.

https://help.mikrotik.com/docs/spaces/R ... /Scripting

So unless anyone knows otherwise, I will presume that is the problem and solution. Thanks again.
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 8:43 pm

Hmm, and there is no script error in logs if :return is called from code that is not in function scope? I can bet that was happening before and I needed to decuple code into functions to avoid that. Maybe it is fixed in some later ROS ver...
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 8:50 pm

RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?
Original title, for future reference

Why did you write RouterOS BUG???
Before writing something like that, wouldn't it be better to first ask for advice on the bugs you have?

Do you like large fonts?

Artificial deficiency and other frills greatly diminish intellectual capacity.

Don't you have the slightest ability to notice that the real difference between the first two scripts is the completely useless and ridiculous presence of ":return"???

Whatever AI you used, it can't fill your gaps, and neither can your intuition.

Thanks for the positive feedback. 😂 Turns out ":return" is not "useless and ridiculous" but just must provide a value (unlike many other languages). You could have said that if you realized it. If you did not realize it either, then we were together on that, so you can join the club.

I also strongly disagree about your implications on AI. I have never coded for RouterOS yet in just 1-2 days I have been able to mostly configure a Mikrotik router with the assistance of AI. I don't have weeks or months to learn the language. I have days to get production code running. The assistance it has provided has been invaluable.

This would be then the first mistake it made where neither Grok nor ChatGPT could see the problem. (They both believed ":return" without value was okay.) This is likely as there are only 3 examples of ":return" in the documentation so they likely inferred from other languages where this is common without much to work from that ":return" alone is adequate. Which I can't really fault them too much for.
Last edited by jonjm on Thu Apr 10, 2025 8:56 pm, edited 1 time in total.
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 8:55 pm

If you did not realize it either, then we were together on that, so you can join the club.
He knows that, for sure :)
Last edited by optio on Thu Apr 10, 2025 9:30 pm, edited 2 times in total.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 3321
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 9:06 pm

I also strongly disagree about your implications on AI. I have never coded for RouterOS yet in just 1-2 days I have been able to mostly configure a Mikrotik router with the assistance of AI. I don't have weeks or months to learn the language. I have days to get production code running. The assistance it has provided has been invaluable.
Please ask therefore these LLMs to correct themselves.
On the other hand, as you saved so much time, you have time to learn that language polishing these scripts by yourself.
Many of forum users mastered it and got the knowledge keepeing their noses to the grindstone.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12980
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 9:38 pm

...and without ever once using artificial deficiency to learn it...


And of course the author continues to write posts that seem to be written in the same style as ShatGPT... look how conditioned he is...

He probably didn't even read my post, let alone understood EVERYTHING that was written...
Such as the complete uselessness of using :return (as also mentioned by @optio) which should be removed, not corrected.
BUT it will probably now ask the Artificial Deficiency the difference between corrected and removed, so it learns it sooner.
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 9:54 pm

@jonjm this :return issue is still present as I described above, so your script will produce error log on return if script is not executed from CLI (Terminal), eg. directly from Winbox/WebFig GUI or scheduler.
return-scripts.png
script-logs.png
You do not have the required permissions to view the files attached to this post.
Last edited by optio on Thu Apr 10, 2025 9:57 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12980
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 9:57 pm

I have days to get production code running.
I wouldn't hire you if you were the last person left.
And if I saw any of my employees do something like that, I would have already fired them for incompetence.

They both believed ":return" without value was okay.
Any intelligent person who reads the documentation will deduce that something must be "returned", also because in the examples there is always something specified...

This is likely as there are only 3 examples of ":return" in the documentation
And in all 3 cases, something is always specified.




You should know that the model is probably trained mostly on scripts on forum than only the docs, because I and a very few others (who I thank but I won't list now because I would surely skip someone) have written and published scripts, the documentation alone would not be enough.

So don't think you can teach me something in this regard (maybe in others yes), at most you can learn from me, but I don't throw pearls before pigs, it's already a lot if I answered you that :return is absolutely useless for how it has been used.
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 11:17 pm

I have days to get production code running.
I wouldn't hire you if you were the last person left.
And if I saw any of my employees do something like that, I would have already fired them for incompetence.

They both believed ":return" without value was okay.
Any intelligent person who reads the documentation will deduce that something must be "returned", also because in the examples there is always something specified...

This is likely as there are only 3 examples of ":return" in the documentation
And in all 3 cases, something is always specified.




You should know that the model is probably trained mostly on scripts on forum than only the docs, because I and a very few others (who I thank but I won't list now because I would surely skip someone) have written and published scripts, the documentation alone would not be enough.

So don't think you can teach me something in this regard (maybe in others yes), at most you can learn from me, but I don't throw pearls before pigs, it's already a lot if I answered you that :return is absolutely useless for how it has been used.
😂😂😂👍
Wow bro. I would feel bad for anyone hired by you if that's how you communicate about programming. Do you really think calling people "pigs" on a forum to discuss coding software is appropriate or useful conduct?
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Thu Apr 10, 2025 11:20 pm

I also strongly disagree about your implications on AI. I have never coded for RouterOS yet in just 1-2 days I have been able to mostly configure a Mikrotik router with the assistance of AI. I don't have weeks or months to learn the language. I have days to get production code running. The assistance it has provided has been invaluable.
Please ask therefore these LLMs to correct themselves.
On the other hand, as you saved so much time, you have time to learn that language polishing these scripts by yourself.
Many of forum users mastered it and got the knowledge keepeing their noses to the grindstone.
Realistically, I program in 5-6 languages. There is only so much time in the day. AI has been a game changer for me in terms of quick pickup of things when I don't have 3 months to master them. This is the only script and configuration task I have not been successful with, and absolutely I could not have done so quickly without the LLM's. Even now I am on borrowed time, but hopefully I can sort it out.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 3321
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 11:26 pm

It's not an explanation that you have no time. Find it. It's easy to steal poeples' sacrificied time using LLMs. Put your effort and teach LLMs for free.
 
jaclaz
Forum Guru
Forum Guru
Posts: 2618
Joined: Tue Oct 03, 2023 4:21 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 11:40 pm

Only for the record, noone was actually called pig, it is Matthew 7:6, which has become a common saying in many languages, not to be taken literally.
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt? (SOLVED: must :return SOMETHI

Thu Apr 10, 2025 11:54 pm

@jonjm this :return issue is still present as I described above, so your script will produce error log on return if script is not executed from CLI (Terminal), eg. directly from Winbox/WebFig GUI or scheduler.

Thanks again. I see what you are referring to. Here are my own tests to illustrate the behavior, which I presume is some type of RouterOS bug then:

TEST 1:

OUTPUT:

From Webfig CLI command (OKAY):
11:16:43 script,warning cloudflare test 1
11:16:43 script,warning cloudflare test 2

From scheduler (OKAY):
11:17:19 script,warning cloudflare test 1
11:17:19 script,warning cloudflare test 2
/system script set cloudflare_ddns source={
:log warn "cloudflare test 1";
:local main do={
:log warn "cloudflare test 2";
:return "done";
:log warn "cloudflare test 3";
};
$main;
};
/system script run cloudflare_ddns; 

TEST 2:

OUTPUT:

From Webfig CLI command (OKAY):
11:15:27 script,warning cloudflare test 1
11:15:27 script,warning cloudflare test 2 true

From scheduler (BUG):
11:14:09 script,warning cloudflare test 1
11:14:09 script,warning cloudflare test 2 true
11:14:09 script,error executing script from scheduler failed, please check it manually
/system script set cloudflare_ddns source={
:log warn "cloudflare test 1";
:local now [/system clock get time];
:local sec [:tonum [:pick $now 6 8]];
:if ( $sec > -1) do={
    :log warn "cloudflare test 2 true";
    :return "done";
} else={
    :log warn "cloudflare test 2 false";
    :return "done";
};
:log warn "cloudflare test 3";
};
/system script run cloudflare_ddns; 
CHECK LOGS
/log print where message~"cloudflare"

SET TO RUN EVERY 10 SECONDS
/system scheduler add name=cloudflare_ddns_update interval=10s on-event="/system script run cloudflare_ddns"
/system scheduler set cloudflare_ddns_update interval=10s on-event="/system script run cloudflare_ddns

So as a workaround I will need to rethink things to avoid this as I do need this to run on schedule. I am not sure how harmful this error is, given it does seem to debug out what we asked it. Perhaps it is not too meaningful. I'm not sure.
 
jonjm
just joined
Topic Author
Posts: 9
Joined: Mon Apr 07, 2025 9:22 am

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Fri Apr 11, 2025 12:18 am

Everyone in this thread's favorite buddy ChatGPT just offered a workaround to the scheduler "return" warning bug:

Return version (bug on scheduler run):
/system script set cloudflare_ddns source={
:log warn "cloudflare test 1";
:local now [/system clock get time];
:local sec [:tonum [:pick $now 6 8]];
:if ( $sec > -1) do={
    :log warn "cloudflare test 2 true";
    :return "done";
} else={
    :log warn "cloudflare test 2 false";
    :return "done";
};
:log warn "cloudflare test 3";
};
/system script run cloudflare_ddns; 
This gives (from scheduler):
11:14:09 script,warning cloudflare test 1
11:14:09 script,warning cloudflare test 2 true
11:14:09 script,error executing script from scheduler failed, please check it manually

"Error" Workaround
/system script set cloudflare_ddns source={
:log warn "cloudflare test 1";
:local now [/system clock get time];
:local sec [:tonum [:pick $now 6 8]];
:if ( $sec > -1) do={
    :log warn "cloudflare test 2 true";
    :error "cloudflare test 2 true ERROR";
} else={
    :log warn "cloudflare test 2 false";
    :error "cloudflare test 2 false ERROR";
};
:log warn "cloudflare test 3";
};
/system script run cloudflare_ddns; 
This gives (from scheduler):

11:41:39 script,warning cloudflare test 1
11:41:39 script,warning cloudflare test 2 true

So we at least dodge the warning on scheduler run this way and still avoid hitting the third log statement.
 
CGGXANNX
Long time Member
Long time Member
Posts: 510
Joined: Thu Dec 21, 2023 6:45 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Fri Apr 11, 2025 12:19 am

Stop calling it a bug and read the doc please https://help.mikrotik.com/docs/spaces/R ... -Functions.

The :return command is only defined for returning a function value from within a function. Which means it requires a value as argument, and the text content of a script is not a function definition. How a function is to be defined is stated in the linked section with examples.

When you use :return outside of the supported scope of a function body, you are in the land of undefined behaviors. I read that you've bragged about knowing 5-6 languages, then you probably know what undefined behavior is, old C has a lot of that. When you do something unsupported then you may get a runtime error or maybe not. In the case of RouterOS, executing script from the command line and from scheduler or from the WinBox dialogs are different contexts and this is also well known (that's why there's a separate command for SSH to be used in non-interactive context, for example https://help.mikrotik.com/docs/spaces/R ... SH-SSHexec). When you do something unsupported then don't complain that the undefined behavior is different in different contexts.

Again: If you are not familiar with the docs, and your only source of knowledge are LLMs, stop calling what you don't know "bugs"!
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Fri Apr 11, 2025 1:46 am

Still IMO rsc is missing then quit/exit command to abort execution without error(:error) to avoid workarounds putting code into function just to exit script by some condition.
 
optio
Forum Guru
Forum Guru
Posts: 1078
Joined: Mon Dec 26, 2022 2:57 pm

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Fri Apr 11, 2025 2:14 am

@jonjm that cannot be true, unless you removed script error logging, :error command aborts script with error which is logged unless script is executed from CLI.
error-scheduler.png
error-scheduler-log.png
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12980
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RouterOS Bug - Why Do These Simple Scripts Break? Cause of Mysterious "value:" Prompt?

Fri Apr 11, 2025 10:49 am

@optio
Don't waste your time ("throwing pearls before swine" is rightly a saying that could be misinterpreted by artificial intelligences...)

He's focusing on how to leave useless :return instead of understanding that must be removed as he's told from the post #3 (...#2...).

Obviously he also knows the other 5/6 languages ​​in the same way...

If you don't talk to him in ShatPT style he won't understand you.


My intervention in this topic ends here, given the complete uselessness of this entire discussion.