-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
Ability to call with error test. #96529
base: master
Are you sure you want to change the base?
Conversation
87f79c1
to
dcd615b
Compare
Why the err variable?
Seems to be redundant to be declared before the call. Can it be declared inside the |
Would you suggest returning an array, or how would you return both the value and the error? This would also make the call harder to adapt to existing code by having you extract the return |
I was suggesting returning an object with
You wont event need to ask |
That's more clear, thank you, but I think it still makes the code more convoluted |
@jcostello The call can return a value if the function returns a value, so the return is needed. |
Adds a new function Object.call_with_error_test Allows to tell if the call of a function fails and the reasons behind the failure. Should help better implement unit tets and other situations.
dcd615b
to
d104c4f
Compare
Will error messages emitted by the failing call be silenced? |
I was implying to have the error declared inside the |
I concur, it makes it really C-like. Is it the first API where we pass an error? |
I'm not sure if the approach here is ideal, I see a few flaws with it. Consider the following example: @tool
extends EditorScript
func _run():
print("beg run")
var err := CallErrorInfo.new()
call_with_error_test(err, "a")
prints("err", err.get_call_error())
print("end run")
func a():
print("beg a")
b()
print("end a")
func b():
print("beg b")
c()
print("end b")
func c():
print("beg c")
var x = self
x.nope()
print("end c") The first issue I see is that this breaks compatibility in terms of how errors are treated and propagated. In current stable (4.3) the call to If we remove this change in behavior, then the test call in this example will not be useful, because If we try The other problem is the interface as some already pointed out. Passing an object is common in C/C++ but not in GDScript. I would suggest just returning an array with the first element being the value and the second being the error result (which may be just an For this to work as intended and be useful I would say it requires these points:
This is almost like exceptions in a way, but without the overhead of actual exceptions. Also, I would consider making this a GDScript construct instead of being an Object/Callable method. This way we could even consider having a different call flow when this is used. Would also be easier to validate the call at compile time. |
At some point between 4.0 and 4.1 we broke (or fixed) this. |
Adds a new function Object.call_with_error_test
Allows to tell if the call of a function fails and the reasons behind the failure. Should help better implement unit tets and other situations.
Usage example:
Alternatively, to avoid strings: