Pcall vs ypcall in output pane

I forgot to put a closure in this code

So I get this error

And while I know that ypcall is an alias for pcall, if I didn’t this error message would look rather cryptic since there is no call to ypcall in my entire source base.

2 Likes

worth mentioning that you don’t need a closure here

pcall(DS.UpdateAsync, DS, playerId, p.update_fn)
2 Likes

That is a good tip but why is it

pcall(DS.UpdateAsync, DS, playerId, p.update_fn)

instead of

pcall(DS:UpdateAsync, playerId, p.update_fn)

or are both actually right because : hides the self param.

Calling thing:func() is syntactic sugar for thing.func(thing)

So yes. :123:

1 Like

:swag:

that’s been established already. The point of this thread is that the error message that’s generated when you make that mistake is misleading.

1 Like

If you do Obj:Method you need to end it with brackets.
You can’t do stuff like local idk = game:Destroy that’s not how it works.
(although it might be nice… and very weird to implement too, but eh)

Little bit more on-topic:
I thought they internally just basicly linked pcall to ypcall.
With “make pcall work like ypcall” they meant “turn pcall into ypcall”.
They miiiight want to fix that error message at least.

pcall is the same as ypcall. It’s exactly the same call on the C-side. For this reason, I’ve changed the error to:

ypcall/pcall requires at least 1 argument

However, this may still be deceptive. Does anyone have any suggestions before I commit to this course of action?

1 Like

This seems reasonable to me. If anything, I would switch the two; pcall is used a lot more than ypcall.

3 Likes
> game:findFirstChild()
10:43:13.598 - Argument 1 missing or nil
10:43:13.599 - Script 'game:findFirstChild()', Line 1
10:43:13.600 - Stack End

Seems fine

This was a nit-picky one anyways.

1 Like

With help from @Seranok, the output will now look like this!

> pcall()
15:35:35.202 - pcall():1: bad argument #1 to 'pcall' (function expected, got no value)
15:35:35.202 - Script 'pcall()', Line 1
15:35:35.203 - Stack End
> ypcall()
15:35:38.548 - ypcall():1: bad argument #1 to 'ypcall' (function expected, got no value)
15:35:38.549 - Script 'ypcall()', Line 1
15:35:38.549 - Stack End
> ypcall(nil)
15:35:41.947 - ypcall(nil):1: bad argument #1 to 'ypcall' (function expected, got nil)
15:35:41.948 - Script 'ypcall(nil)', Line 1
15:35:41.948 - Stack End
> pcall(nil)
15:35:44.123 - pcall(nil):1: bad argument #1 to 'pcall' (function expected, got nil)
15:35:44.123 - Script 'pcall(nil)', Line 1
15:35:44.124 - Stack End
15:35:49.366 - Auto-Saving...
> local x = pcall x(nil)
15:36:06.057 - local x = pcall x(nil):1: bad argument #1 to 'x' (function expected, got nil)
15:36:06.058 - Script 'local x = pcall x(nil)', Line 1
15:36:06.058 - Stack End
> ypcall("")
> print(ypcall())
15:36:55.226 - print(ypcall()):1: bad argument #1 to 'ypcall' (function expected, got no value)
15:36:55.227 - Script 'print(ypcall())', Line 1
15:36:55.227 - Stack End
> print(ypcall(""))
false attempt to call a string value
4 Likes