-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Change unsafe
keyword to trust
#296
Comments
This can be a part of other breaking design changes that we should batch together to avoid forcing people to update their scripts every single time |
imo we should make our own error handling that would output a nice error in the terminal, like this:
amber_error() {
echo "\x1b[31mRuntime error!\x1b[0m" > stderr
echo "$1" > stderr
}
amber_run_cmd() {
ret=$($@)
AS=$?
if [ "$AS" != "0" ]; then
amber_error "Command $1 exited with code $AS!"
exit $AS
fi
echo $ret
}
amber_run_cmd do_stuff
do_stuff
do_stuff
AS=$?
if [ "$AS" != "0" ]; then
echo oh no
fi |
This makes no sense @b1ek as there is |
thats not at all what i was talking about. lets view the error codes as exceptions in usual programming languages. right now amber recommends the following approach: handle the exception manually in a sort of function block. that will cause inconsistency between how different users implement the failed block. its pretty much the same thing as if rust wouldn't have let data = match res {
Ok(v) => v,
Err(err) => { println!("{err:?}"); exit(1) } // this can clearly be implemented in an undefined amount of different ways
} you can clearly see that its: 1. not very comfortable to use; 2. causes the user to implement error handling themselves, which will be different and breaks DRY. this is something that is always been handled by the language, each time you |
There are unwraps in Amber and these are called
|
Inconsistencies in how different programmers write code is immanent in any language. I don't see any possible solution to standardize how people would want to handle errors. But I can agree that there could be a usecase for a method to stop the script immediately without possible recovery. Something like |
Actually |
The appropriate keyword for this use case would be However I looked up how the keyword
In Amber world this would mean a command that does not fail by exiting with code other than zero but rather requires additional command to see if the previous command failed. The good example would be
In Amber world this would also mean that if programmer is sure that this command will work - then they can run this command unsafely without handling any error. SummaryI think that the keyword |
Let me illustrate with an example:
We have 2 usecases of let array: [i32; 2] = [0; 2];
unsafe {
array.get_unchecked(10);
}; unsafe in rust is truly unsafe, because when you use it, rust compiler can't guarentee that everything will work fine. If you are smart, like in the first example and know that there's nothing to fear, go ahead and do it. But if you didn't think of everything and the command fails, there should be |
@KrosFire do you propose any better idea for this keyword? |
I think that this behaviour is better described by But if we want |
Assume sounds good. This issue need to also cover update in the docs and in the plugins. In the compiler if „unsafe” encountered let’s tell user to use „assume” instead and spit out an error |
I don't like I am thinking for something like |
unsafe
keyword to ignore
unsafe
keyword to something else
unsafe
keyword to something elseunsafe
keyword to trust
The community has chosen the |
According to docs:
"""
unsafe
- the discouraged way to handle failing. This modifier will treat commands as if they have completed successfully and will allow them to be parsed without any further steps."""
The way the
unsafe
keyword works, seems pretty safe to me. I'd think, that if I useunsafe
keyword my program can crash at this point, because it's not safe and I don't handle possible errors. But all it does is it ignores any potential failures and keeps going. While it can be "unsafe" in a long run, it's not very intuitive (imho).I think that a better keyword for this behaviour is
ignore
or some variation of it.Oh, and one more thing. "will treat commands as if they have completed successfully and will allow them to be parsed without any further steps.". I believe this sentence is incorrect. It should be something like this:
"will treat commands as if they have completed successfully and will run further code"
So we're sticking with
trust
keyword then.trust
to the list of keywords for Visual Studio Code Extension amber-vsc#1trust
to the list of keywords for Zed Extension amber-zed#1unsafe
the code works but gets deprecation warningThe text was updated successfully, but these errors were encountered: