-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Start using [[nodiscard]]
in Core to remind callers to handle errors
#11738
Comments
|
Yes, most of |
[[nodiscard]]
in Core to coax callers to handle errors.[[nodiscard]]
in Core to remind callers to handle errors.
I think that it should be part of more of a holistic approach to dealing with various problems, |
Fully agreed that we'll need other techniques to have a holistic approach for problems! For Especially, it will be useful in code review because it exposes the chosen strategy. I think that makes it very suitable for this problem specifically. |
[[nodiscard]]
in Core to remind callers to handle errors.[[nodiscard]]
in Core to remind callers to handle errors
Describe the project you are working on
Godot engine reliability.
Describe the problem or limitation you are having in your project
Some Godot types can error out of functions early. In this case, often the expected invariants of the called function are broken.
To make a clear example:
There are many other instances where this can lead to a crash:
Just as an example, there have recently been some 'mysterious' crashes around indexing errors this may help make less mysterious, e.g.:
It should be noted that in most cases where
Error
is produced, it is also immediately logged and should be part of the error log. However, even in that case, forcing proper error handling may help debug the issues and eliminate possible paths of failure.Describe the feature / enhancement and how it helps to overcome the problem or limitation
A feature exists in C++ to handle this kind of situation:
[[nodiscard]]
(C++17). Godot should use[[nodiscard]]
internally where appropriate, to remind callers to handle errors explicitly.In some cases, it is appropriate to simply log an error and exit the function early and gracefully:
Error error = function(); ERR_FAIL_COND(error);
In other cases, a crash is warranted because it's impossible to handle the situation gracefully. In this case, the program should exit with an appropriate, easy to understand error message.
Error error = function(); ERR_CRASH_COND(error);
(more appropriate macros should be chosen, depending on the situation)
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Define functions with
[[nodiscard]]
like so:If the function is called without handling a potential error (or explicitly ignoring it), the compiler will complain:
If this enhancement will not be used often, can it be worked around with a few lines of script?
It's a systematic issue.
Is there a reason why this should be core and not an add-on in the asset library?
It's core.
The text was updated successfully, but these errors were encountered: