CC: Tweaked

CC: Tweaked

65M Downloads

Coroutine resume will mess up string error

zyxkad opened this issue · 2 comments

commented

Minecraft Version

1.20.1

Version

1.114.2

Details

coroutine.resume and pcall seems will automatically add a location prefix of where the error happens.

ok, err = coroutine.resume(coroutine.create(function() error('a string') end))
print(ok)
print(err) -- lua[1]:1: a string

but this code won't have location included

ok, err = coroutine.resume(coroutine.create(error), 'a string')
print(ok)
print(err) -- a string

it also will not append the prefix if the error is a number or table

I don't really like this because it

  1. have unknown behaviour based on type & stacktrace
  2. can have duplicated traceback with customized errors
commented

alr thanks

commented

This matches PUC Lua behaviour. You can call error("a string", 0) to prevent the position being prepended.

ᐅ lua
Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio
> ok, err = coroutine.resume(coroutine.create(function() error('a string') end))
> print(ok, err)
false	stdin:1: a string
> ok, err = coroutine.resume(coroutine.create(error), 'a string')
> print(ok, err)
false	a string
>