question

oskar avatar image
oskar asked

When catching internal errors the caught Error is always empty

Hi,

I'm trying to implement some error handling in my cloudscript. I'm doing it by wrapping all my internal functions in a function that does try/catch and writes the caught error to the players playstream. My problem is that however I'm constructing the Error myself or forcing PlayFab to throw one, all I get in my generic try/catch function is "{}". I am JSON.stringifying the caught err btw.

Also tried with just a straight up try/catch (no fancy wrapping) and same, just "{}". Can somebody tell me what's going on here?

Title ID I'm testing this on: 78CC

Also, what would be the reason the playstream does not include cloud script errors for players? When I test run cloudscript from Game Manager and they throw errors it does produce a nice playstream event with error info that's extremely useful to hunt down bugs. But when the call comes from a client there's no errors in the stream, only in the response to the client.

Many thanks, Oskar

CloudScript
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Hi, could you please point out the code of error handling so we can investigate, like which revision, which function?

And, for the second issue about throwing errors, similarly, could you please point out which revision and function that is having it?

0 Likes 0 ·
oskar avatar image oskar Citrus Yan commented ·

The error handling would be title 78CC, revision 266, functions TestTryCatch****. One function uses my wrapper function, the other a normal try/catch, same result.

Regarding the playstream not showing cloudscript execution errors, that would be on our Live title 64A68. As an example I've seen plenty of javascript errors for player 213A3CD917163073 in an external error reporting system we use (Raygun) but looking at this players event history there are no errors. Worth noting is I said first that there were no errors in the players playstream but obviously I didn't have a particular live players playstream open when the error occurred so what I meant was the event history.

Thanks.

Edit: To answer your 2nd question fully. Title 64A68, revision 22 (Live). We've seen player 213A3CD917163073 receiving errors when trying to call our OpenHatchedItem handler but event history shows nothing having gone wrong.

0 Likes 0 ·

1 Answer

·
oskar avatar image
oskar answered

So, apparently it's a thing that you can't serialize Javascript Error. You learn something new every day huh. Explanation:

only enumerable properties will be serialized.

Error object doesn't have any enumerable properties so hence produces just "{}" when serialized. It's possible to get around this like so:

JSON.stringify(err, Object.getOwnPropertyNames(err))

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

oskar avatar image oskar commented ·

@Citrus Yan Yes, that's correct.

Edit: I just discovered the GeneratePlayStreamEvent flag you can set in the request to ExecuteCloudscript. That helped...

We'll switch that on for next release and see. If it generates too many events to the point that it obfuscates rather than helps we'll have to re-visit.

0 Likes 0 ·
franklinchen avatar image franklinchen commented ·

Good to see Citrus's suggestion works, let us know if you still have issue

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan commented ·

Oh, glad you solved the first problem:)

For the second problem, I can't see any "player_executed_cloudscript" events in player 213A3CD917163073's event history, and, even more, I can't any of them in [Game Manager] -> [Data] -> [Event History] as well, which might be a problem. To be sure, your clients are using Client/ExecuteCloudScript API to call your handlers, is that right?

-1 Like -1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.