zapier / zapier-platform

The SDK for you to build an integration on Zapier

Home Page:https://platform.zapier.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Circular JSON throws an error in logger

xavdid opened this issue · comments

Bug Description

(copied from Stack Overflow)

If a request's response has a circular reference, then JSON.stringify will throw.

Reproduction Steps

> let o = {}
undefined
> o.a = o
{ a: [Circular] }
> o.a.a.a
{ a: [Circular] }
> JSON.stringify(o)
Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'a' closes the circle
    at JSON.stringify (<anonymous>)

Logging JSON with that structure yields:

== Log
Unhandled error: TypeError: Converting circular structure to JSON
What happened:
  Starting POST request to https://photoslibrary.googleapis.com/v1/uploads
  Received 200 code from https://photoslibrary.googleapis.com/v1/uploads after 193ms
  Received content "redacted"
  Converting circular structure to JSON
TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at sendLog (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/tools/create-logger.js:166:16)
    at logResponse (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/http-middlewares/after/log-response.js:71:10)
    at Object.collector.then.newOutput (:censored:9:d1ba0cf2aa:/node_modules/zapier-platform-core/src/middleware.js:80:37)
    at bound (domain.js:402:14)
    at Object.runBound (domain.js:415:12)
    ...

I'm not sure how we get such a thing in an HTTP response, but we should be more defensive about it.

This was fixed by #214, which was released in zapier-platform-core 10.0.0. So for anyone who runs into this issue and still uses 9.x, upgrade to the latest core.