love.filesystem.load() doesn't catch syntax errors?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
NetherGranite
Prole
Posts: 30
Joined: Wed Jul 11, 2018 11:08 pm

love.filesystem.load() doesn't catch syntax errors?

Post by NetherGranite »

loadfile() catches syntax errors, but love.filesystem.load() does not, meaning that calls to it have to be wrapped in pcall or xpcall if you are not sure whether the file you are loading is error-free. Is this intentional? I assumed love.filesystem.load() would use loadfile() internally, just with the added functionality of searching for the file in more places; am I wrong?
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love.filesystem.load() doesn't catch syntax errors?

Post by zorg »

According to the code, love.filesystem.load should indeed catch most errors: https://bitbucket.org/rude/love/src/992 ... #lines-604

(Also, it uses PhysFS under the hood, like the rest of love.filesystem)

Maybe give us a testcase where it fails for you?
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
NetherGranite
Prole
Posts: 30
Joined: Wed Jul 11, 2018 11:08 pm

Re: love.filesystem.load() doesn't catch syntax errors?

Post by NetherGranite »

zorg wrote: Sat Nov 17, 2018 7:48 pm Maybe give us a testcase where it fails for you?
main.lua:

Code: Select all

love.filesystem.load("file.lua")
file.lua:

Code: Select all

a
Running this project throws this error:

Code: Select all

Error

main.lua:1: Syntax error: file.lua:2: '=' expected near '<eof>'



Traceback

[C]: in function 'load'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
User avatar
NetherGranite
Prole
Posts: 30
Joined: Wed Jul 11, 2018 11:08 pm

Re: love.filesystem.load() doesn't catch syntax errors?

Post by NetherGranite »

Is bumping this thread appropriate?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: love.filesystem.load() doesn't catch syntax errors?

Post by grump »

NetherGranite wrote: Sat Nov 17, 2018 8:12 pm main.lua:

Code: Select all

love.filesystem.load("file.lua")
file.lua:

Code: Select all

a
Running this project throws this error:

Code: Select all

Error

main.lua:1: Syntax error: file.lua:2: '=' expected near '<eof>'



Traceback

[C]: in function 'load'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
There is probably an error, but you're not doing anything with that information. Try

Code: Select all

assert(love.filesystem.load("file.lua"))
If load returns nil, it also returns an error message.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 149 guests