multitheftauto / mtasa-blue

Multi Theft Auto is a game engine that incorporates an extendable network play element into a proprietary commercial single-player game.
https://multitheftauto.com
GNU General Public License v3.0
1.38k stars 425 forks source link

Add option to treat warnings as errors #3737

Open CrosRoad95 opened 7 hours ago

CrosRoad95 commented 7 hours ago

Is your feature request related to a problem? Please describe.

Steal i mean, borrow concept of treating warnings as errors. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-warnings

Describe the solution you'd like

Assign id to every warning, add option to treat them as errors, for example: setElementPosition(false, 0, 0, 0) - WARNING: [1] server.lua:1: Bad argument @ 'setElementPosition' [Expected element at argument 1, got boolean] where "[1]" is id of warning. But in practice this should be an error. so, you go to mtaserver.conf, find and add warning: 1, next time code will stop execution and you will see error instead of continuing execution

This is 101% backwards compatible

Describe alternatives you've considered

/

Additional context

/

Security Policy

TracerDS commented 5 hours ago

Appendum: Make a way to catch warnings too

CrosRoad95 commented 5 hours ago

Warnings are just warnings, like you put "0" instead of 0, mta converted it but you should use numeric zero, not string, or like example i gave before: setting position of something what is not element should be error, but isn't, there is many such cases, we can not change it because even if your code is broken, we can not break your broken code.

Again, this warning above can cause server/client to fall into invalid state, let's say after you set position you print log to admin, but this log doesn't depend on this element - "platform was moved", now you get log, but imaginary platform didn't move. You can see in logs both but if you have tons of logs you may get lost

TracerDS commented 5 hours ago

I mean, if a warning is thrown then most of the time the function returns false so you can check against that.

CrosRoad95 commented 5 hours ago

you can check against that.

Yes, you can, but making code in shape of pyramid of doom is not good

TracerDS commented 5 hours ago
if (!setElementPosition(...)) then
    error("Invalid args")
end

? In some cases, it is unavoidable. This is the way if you want to have errors when warning is thrown

CrosRoad95 commented 4 hours ago
if (!setElementPosition(...)) then
    error("Invalid args")
end

? In some cases, it is unavoidable. This is the way if you want to have errors when warning is thrown

Yes, and you double your codebase, i probably prefer to just fork mta and replace all warnings with errors instead of dealing with that shit