Error() Function not working

I have this function that parses an error message, but when it’s called it doesn’t halt the thread or print an error message.

function Report(Line: number, Where: string, Message: string)
    --<< Put this here to check if the function was being run, and with the correct params.
	print("\n[line " .. Line .. "] Error" .. Where .. ": " .. Message) 
    -- >>
	
	error("\n[line " .. Line .. "] Error" .. Where .. ": " .. Message)
end

It runs the print function, but the error function never happens, no red text shows up, and the thread continues running.

This had been working, and then randomly stopped without me changing anything.

Where’s the function being called from? If it is called from within a pcall, it may prevent the error message from being displayed

Why would you call error after print? It should be error before print so it could halt a thread

If you want line numbers, consider using debug.info instead.

function Report(Where: string, Message: string)
	local Line = debug.info(2,"l") -- 2 represents what line Report was called from, l represents line number
	print("\n[line " .. Line .. "] Error" .. Where .. ": " .. Message)
end

If I call Report from line 10, it will print line 10. Notice that I removed the line argument from your function call and replaced it with debug.info.

It was for testing if the correct params where being passed through.

I added it after the error function stopped working to make sure it wasn’t how the Report function was being used that was causing it to not work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.