Skip to content

Allow erroring in LuaRequire returns #581

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

Open
cheesycod opened this issue May 15, 2025 · 5 comments · May be fixed by #582
Open

Allow erroring in LuaRequire returns #581

cheesycod opened this issue May 15, 2025 · 5 comments · May be fixed by #582

Comments

@cheesycod
Copy link

cheesycod commented May 15, 2025

Apparently, it is safe to raise an error in a luau require method so it would be nice if NavigateError had a Error variant that just errors with said error. As for use-cases, better/more user friendly errors when handling typo'd registered modules or just doing resolution in general (e.g. foo is not a valid builtin module instead of @abc is not a valid alias as an error etc.)

I actually got this working on a fork of mlua which I'm planning of PRing for reference

@cheesycod cheesycod linked a pull request May 15, 2025 that will close this issue
@khvzak
Copy link
Member

khvzak commented May 15, 2025

I would recommend opening FR directly in luau-lang/luau to get proper support from the language.

@cheesycod
Copy link
Author

I would recommend opening FR directly in luau-lang/luau to get proper support from the language.

Ah alright, though I think the advice they’ll say is to just use lua_error for this but it’s worth a shot ig

@cheesycod
Copy link
Author

For context, the reason I found out about this is because lute (c++ runtime) uses this strategy of using lua_error in require to error with user friendly errors like:

Image

@khvzak

@khvzak
Copy link
Member

khvzak commented May 15, 2025

In the require's navigator implementation they already have some (private) concept of errors, including error handler.
For example, before triggering luaL_error, they add prefix error requiring module "<some name>": to error messages.
There is a chance they want to change API and extend luarequire_NavigateResult with something like NAVIGATE_ERROR and prefer errors returned some other way than through exception.
The require API already has breaking changes almost every release, so better to confirm earlier than after stabilizing the API.

@cheesycod
Copy link
Author

cheesycod commented May 15, 2025

@khvzak

So I asked someone in the Luau team and here is the response I got regarding this:

I would just stick with lua_error, the only ones defined in Require.h are the ones we've explicitly discussed in RFCs: file not found or ambiguity with module representation (mymodule.luau = mymodule.lua = mymodule/init.luau = mymodule/init.lua).

Overall, not so hopeful on them changing the API with a specific NavigateError as they seem to endorse lua_error right now but I'm willing to wait a bit for something more official too.

The only issue I have personally with lua_error though is RawLua memory leaks so it'd be nice if those could be solved first somehow. Although I am unsure if the RawLua memory leaks are caused by luau require (which is where I believe the memory leaks usually start from) or from the use of RawLua itself, the whole issue has made me extremely scared of using RawLua in general especially where exceptions are involved...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants