[Bug] failed command expression is not sending output to variable
The docs for command-expressions say: "Command expression result is sent to the variable instead of standard output."
This is not true, by running the following code
let result = $cat not_existent.txt$ failed {
echo "Failed to read the file"
}
echo "---"
echo result
You can see that the message is actually sent to standard output and is not saved in the result variable.
Is this an error in the amber language or an error in the docs?
In this case I think that if the code is written:
if file_exists(not_existent.txt) {
let result = unsafe $cat not_existent.txt$
echo "---"
echo result
}
It is like the documentation says. My guess is that only when used failed there is no variable return.
What do you think @b1ek?
I think that this is the stderr that is being show in the console
@bnjmnjrk, you have expected result to be "Failed to read the file", right? there really isnt a way to return a value from a failed block right now, not even with an echo or return so this is a bug that needs fixing
this is the
stderrthat is being shown in the console
nyope, its the 2nd line's echo
is this an error in the amber language or the docs
kinda both, i guess?? docs are not clear how to return a value from a failed block, neither has this been implemented yet
We could add ability to return it from the failed block though:
let result = $cmd args$ failed {
echo "Failed to run this command"
return "failed"
}
And also something like:
let result = $cmd args$ or "failed"
This doesn't need any handler as it's handled by the or keyword that will default to the "failed" value in case of failure.