Skip to content
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

Standardize Error Handling in Builtin Programs #1771

Open
fatboychummy opened this issue Apr 2, 2024 · 2 comments
Open

Standardize Error Handling in Builtin Programs #1771

fatboychummy opened this issue Apr 2, 2024 · 2 comments
Labels
area-CraftOS This affects CraftOS, or any other Lua portions of the mod. enhancement An extension of a feature or a new feature.

Comments

@fatboychummy
Copy link
Contributor

fatboychummy commented Apr 2, 2024

I am currently discussing with Xella the implementation of a feature to detect failed installations for PineStore download tracking. Specifically, if an installation fails, it should not log a download. However, we've encountered an issue with many built-in programs (such as pastebin get/run) not returning an error state directly through error(), but instead using printError().

This poses a challenge as there is no clear indication of installation failure when tracking the program's status. Consequently, since the program consistently returns an OK status, determining if the installation actually failed becomes problematic.

Thus, I would like to go over all builtin CC programs and change any printError's/io.stderr:write()'s into proper error()s. I am, however, not entirely sure how this may affect things overall, so I would appreciate any insights, suggestions, or alternative solutions.

I am not sure of a timeframe on this as well, as I'm running into finals, but I would like to look into this sometime in the next month.

@fatboychummy fatboychummy added the enhancement An extension of a feature or a new feature. label Apr 2, 2024
@SquidDev SquidDev added the area-CraftOS This affects CraftOS, or any other Lua portions of the mod. label Apr 2, 2024
@SquidDev
Copy link
Member

SquidDev commented Apr 2, 2024

Yeah, the lack of a good os.exit(1) alternative is definitely a pain. The trouble with error is there's no good way to tell if something is user-friendly error (where we just want to print it) vs a bug (where we might want to print the context or a stack trace). CC currently does this by checking the error contains a filename and line number, but other shells like mbs don't bother.

The "best" pattern here is probably to display the message normally (printError/io.stderr:write), and then exit with a no-args error().

Edit: Though lua and edit's run wrapper don't handle that very well. Technically the most standard-compliant option is to do error(setmetatable({}, {__tostring = function() return "My error message" end })), but that's even uglier! We could have a helper for this I guess??? Not sure!


As an aside, installers really shouldn't be shelling out to pastebin/wget. Those programs make sense as the entrypoint to an installer, but anything else should just use the http API normally!

@djmattyg007
Copy link

As an aside, installers really shouldn't be shelling out to pastebin/wget. Those programs make sense as the entrypoint to an installer, but anything else should just use the http API normally!

How come?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CraftOS This affects CraftOS, or any other Lua portions of the mod. enhancement An extension of a feature or a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants