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

[Bug] yue.require does not propagate errors to Lua #183

Open
SkyyySi opened this issue Jan 25, 2025 · 2 comments
Open

[Bug] yue.require does not propagate errors to Lua #183

SkyyySi opened this issue Jan 25, 2025 · 2 comments

Comments

@SkyyySi
Copy link

SkyyySi commented Jan 25, 2025

The YueScript documentation says to use yue.require() to perform custom error handling:

local yue = require("yue")
local success, result = xpcall(function()
    yue.require("yuescript_module_name")
end, function(err)
    return yue.traceback(err)
end)

However, this does not work. When throwing an error in a .yue file, the call to yue.require() will not fail and just return nothing. The error handler defined here will not be called, either. Furthermore, yue.require() always prints a traceback with yue.traceback().

Image

The screenshot shows a file called temp.yue that contains the following code:

const f = () ->
	error("Test message")



f()


It is being executed with LuaJIT, with the following code:

yue = require("yue")
print(pcall(yue.require, "temp"))

The output is:

Test message
Stack Traceback
===============
(1) '=(yuescript)':172
(2) global C function 'pcall'
(3) '=stdin':1
(4)  C function 'function: 0x7e8c2865c588'

true nil
@MTadder
Copy link
Contributor

MTadder commented Jan 27, 2025

A concise way I found to test this is:

_G.yue = require("yue")
s, r = xpcall(
    (() -> require("nonexistent_file")),
    ((err)-> print("THIS IS NOT MISSING IN OUTPUT"))
)
s, r = xpcall(
    (()-> yue.require("nonexistent_file")),
    ((err)-> print("THIS IS MISSING IN OUTPUT"))
)

The same error occurs when using pcall.

pigpigyyy added a commit that referenced this issue Jan 29, 2025
@pigpigyyy
Copy link
Member

The yue.require() function was unintentionally swallowing errors, which is inconsistent with Lua's standard require() behavior. To align with Lua's conventions, I've decided to remove this shortcut API and instead provide an example for users to handle module loading properly:

local yue = require("yue")
yue.insert_loader()
local success, result = xpcall(function()
    require("yuescript_module_name")
end, function(err)
    return yue.traceback(err)
end)

I've just pushed a new commit that removes yue.require() and updated the documentation accordingly.

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

No branches or pull requests

3 participants