Hi there, I have a custom code editor that uses Lexer and highlights the tokens. Sometimes it can throw a confusing error saying string expected, got string. I tried to use a pcall function to print out where in the string the error went but I am having trouble as I am using table.concat along with a list of values to set the text property of my textlabel.
local lines
if ishighlighting == false then
lines = string.split(text,"\n")
else
lines = string.split(highlight(text),"\n")
end
local concat
local succ,err = pcall(function()
concat = table.concat(stringtable, "\n")
TextBox.Text = concat
end)
if err then
print(error())
end
task.wait()
It’s actually pretty simple: print(err) Alternatively, you can do error(err). That will print a red error notice in the server output and it will halt the script that threw it. warn() will print a warning notice. In your code print(error()) is, well, an error because error is a print function in of itself.
I tried this print(error(lines[#lines],1)) which seems to print where it cut off, assuming thats where the error went as well as the err itself and got this
It doesn’t work like that. pcall() returns a tuple, which you have accounted for in local succ,err = pcall(function() ..... end). print(), warn(), error() all print stuff. Do not nest an error() call inside a print(), it will not work the way you expect.