adventuregamestudio / ags

AGS editor and engine source code
Other
701 stars 160 forks source link

Standard error/message print in command line tools #2530

Open ericoporto opened 1 month ago

ericoporto commented 1 month ago

When reading error messages from command line tools we may want to be able to understand their errors in ags, so it would be nice to have they print something like Error: at line X in file 'FILE', ERROR_MESSAGE so we could pick this up in the Editor using a regex.

Additionally, it may be nice to also print the tool name, like agfexport:Error: msg, which would make it easier to get from which tool came which error - imagine you are running many tools at once.

Finally some standard error messages like failed to open 'FILE' for reading could be useful since they happen across all tools.

I would suggest adding a small helper file to help make these uniform across tools. I wonder if setting the tool name could be made at compile time using either macro or constexpr, this would avoid having a singleton class. Edit: actually I think it may not be possible to set at compile time differently per tool.

ivan-mogilko commented 1 month ago

I wonder if setting the tool name could be made at compile time using either macro or constexpr, this would avoid having a singleton class. Edit: actually I think it may not be possible to set at compile time differently per tool.

It might be possible, for example, if you have it defined as a compilation variable. Although idk if any of that is necessary. I don't understand how is this related to having or not having a "singleton class" though; which "class" is referenced here?

ericoporto commented 1 month ago

If it was a singleton I would make something like this class here

https://github.com/ericoporto/agsworks/blob/main/src/misc/awlog.h https://github.com/ericoporto/agsworks/blob/main/src/misc/awlog.cpp

But instead of where I init it passing the engine instance I would set the prefix. I don't know if this is a problem at all.

And I know having such prefix is not a common thing in general command line tools, but if you run a bunch of tools once one of them errors it becomes a bit hard to figure where the issue was - specially in "can't open file for writing" and any other types of error messages that could be identical across tools.

It might be possible, for example, if you have it defined as a compilation variable

This is the only working approach I could figure it out.

Anyway, if a singleton isn't a problem at all I think I will go with it instead.

Other approach that could be possible, would be to reuse the log in the engine but I looked at the files of it in Common/debug and couldn't understand how I would do that, I mean, I think I still would need some Log implementation to hide it and to set the handler here, for the actual output implementation.