-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Pin down return value on failure #821
Comments
Okay, so my current POV is that (3) is a good way to go. I think it's nice because it's consistent for every function. Nevertheless, I have been asking for PRs to stick to (2) since that's what is currently done. I am unsure as to whether existing functions should change. I imagine a lot of existing code does |
What do you think about this one? mtasa-blue/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp Lines 890 to 891 in a547e4b
... mtasa-blue/Server/mods/deathmatch/logic/luadefs/CLuaACLDefs.cpp Lines 963 to 966 in a547e4b
I prefer to return nil on failure, no matter the return type (3). |
hasObjectPermissionTo is a getter that returns boolean values, so fits into (2). |
It's not actually a getter, because by definition, it doesn't simply return a private member variable of the player/resource/..., which gets passed to the function. It has to lookup the permission in the ACL for the object and then returns a boolean. |
(2) isn't restricted to getters in that traditional sense, it is more about So because I've edited this issue to reflect this. In fact, hasObjectPermissionTo was ahead of its time, doing (2) before we noticed we needed to do (2). |
I'd prefer another option: Hard error on usage mistakes. For new functions this could be applied easily. Applying this to old functions is a bit tricky since it could break badly written scripts and we'd be willing to break backwards compat (yet another reason for 1.6 ;)) with (wrong) code like |
I would be in support of just erroring. Are there any other situations where we might want to use warnings, or would this eradicate the use of warnings completely? (Ignoring existing functions.) |
We could also add a "strict" mode, which could, if enabled, throw an error for already existing functions. |
Okay, so let's hard error on usage mistakes, as per #821 (comment). Let's also do something like a strict mode (#821 (comment))... how do we want to implement this? Potential ways would be:
|
We could add server-wide, per-resource and per-script. Everyone would be happy. |
Haha that's a joke right? |
Yes, only server-wide and per-resource is enough. |
It's been 3 months, has there been any progress with this? It's blocking a few pull request and doesn't seem like it's going to change soon |
@sbx320 has been working on this — am I fine to assign this to you? |
To clarify the functionality mentioned here is blocking pull requests:
"Strict mode" can be discussed and added later as a separate issue/feature. |
I think what @sbx320 suggested is enough. Throwing hard error on usage mistake is good. The strict mode looks nice, but it might break scripts, and I can only imagine boomers using it. |
Current state: Stuff works, I've gotten stuck on some performance isuse, but that is resolved now. Only missing part now is to handle errors properly (right now the errors are handled, but the messages are empty). Plus a whole bunch of testing obviously. |
I am going to close this issue now. See quote for final decision. Before sbx320's pull request is done, the following code should be fine: if (argStream.HasErrors())
{
return luaL_error(luaVM, argStream.GetFullErrorMessage());
} |
Sounds good! |
What about gathering stats to measure the impact of causing hard errors. i.e. Servers and clients upload info about usage mistakes |
I can't find any downside to gathering more anonymized information with consent of the server owners in order to make a better decision 👍 |
* initial "engineResetModelLODDistance" implementation * Fix simple logic error fDistance is always 0.0f before this condition * Change return logic and add override for LOD maximum distance engineResetModelLODDistance will return false if the LOD distance has not been changed, or it's currently set to its original value. Also allowed for override of the max LOD distance in CModelInfoSA::SetLODDistance * Fix max distance override Forgot to add check to the preprocessing * Move "same value" check to Lua function It wasn't suitable to have the "same value" check in the GetOriginalLODDistance function, this should always return a value if there is one. Instead, we check when executing EngineResetModelLODDistance * Update argStream checking as per #821 Co-authored-by: Patrik Juvonen <patrik@scope.studio>
Recently there seems to be some confusion about what values functions should return when they encounter an error.
Historically, the following has been the general policy; (1):
Somewhere along the way we realised functions that ordinarily return booleans (isPedDead, hasObjectPermissionTo, etc) should not return meaningful values (
false
) when errors are encountered, so we started doing something else for new functions; (2):nil
.false
.Some new functions / pull requests have started to do something else; (3):
nil
on failure, no matter the return type.Things to pin down:
The text was updated successfully, but these errors were encountered: