Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Bug] failed command expression is not sending output to variable

Open bnjmnjrk opened this issue 1 year ago • 4 comments

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?

bnjmnjrk avatar Jun 28 '24 13:06 bnjmnjrk

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?

Mte90 avatar Jun 28 '24 13:06 Mte90

I think that this is the stderr that is being show in the console

Ph0enixKM avatar Jul 07 '24 17:07 Ph0enixKM

@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 stderr that 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

b1ek avatar Jul 11 '24 15:07 b1ek

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.

Ph0enixKM avatar Jul 12 '24 16:07 Ph0enixKM