dynamodb-onetable: Converting circular structure to JSON in logger handling of Exception

I doubt this is an issue with code, but with the construction of the model, but I’ve not been able to figure it out. Hate anyone having to spend time on this, but appreciate any quick pointers.

When creating a new item for table, the following stack trace is generated:

create item error: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'IncomingMessage'
    |     property 'req' -> object with constructor 'ClientRequest'
    --- property 'res' closes the circle
    at JSON.stringify (<anonymous>)
    at Log.logger (file:///var/task/src/handlers/process-badge-scans.js:22:26)
    at Log.process (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Table.js:1003:18)
    at Log.error (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Table.js:993:14)
    at Table.execute (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Table.js:532:30)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Model.run (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Model.js:321:22)
    at async Model.putItem (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Model.js:768:16)
    at async Model.create (file:///var/task/node_modules/dynamodb-onetable/dist/mjs/Model.js:485:22)
    at async addRecords (file:///var/task/src/handlers/process-badge-scans.js:61:21)

Here is the model it is working on:

{
  "indexes": {
    "primary": {
      "hash": "PK",
      "sort": "SK"
    }
  },
  "models": {
    "CLASS": {
      "type": {
        "type": "string",
        "value": "CLASS"
      },
      "PK": {
        "type": "string",
        "value": "TENANT#${tenantId}#${className}"
      },
      "SK": {
        "type": "string",
        "value": "${className}"
      },
      "className": {
        "type": "string"
      },
      "description": {
        "type": "string"
      },
      "tenantId": {
        "type": "string"
      }
    },
    "SECTION": {
      "type": {
        "type": "string",
        "value": "SECTION"
      },
      "PK": {
        "type": "string",
        "value": "TENANT#${tenantId}#${className}"
      },
      "SK": {
        "type": "string",
        "value": "${className}#${sectionNumber}"
      },
      "className": {
        "type": "string"
      },
      "sectionNumber": {
        "type": "number"
      },
      "timeStart": {
        "type": "string"
      },
      "timeEnd": {
        "type": "string"
      },
      "teacher": {
        "type": "string"
      },
      "classroom": {
        "type": "string"
      },
      "weekdays": {
        "type": "Object", "schema": {
          "weekdays": { "type": "Array"}
        }
      },
      "tenantId": {
        "type": "string"
      }
    },
    "ATTENDANCE": {
      "type": {
        "type": "string",
        "value": "ATTENDANCE"
      },
      "PK": {
        "type": "string",
        "value": "TENANT#${tenantId}#${className}"
      },
      "SK": {
        "type": "string",
        "value": "${className}#${sectionNumber}#${classDate}"
      },
      "className": {
        "type": "string"
      },
      "sectionNumber": {
        "type": "number"
      },
      "studentId": {
        "type": "string"
      },
      "badgeInTime": {
        "type": "string"
      },
      "classDate": {
        "type": "string"
      },
      "tenantId": {
        "type": "string"
      }
    },
    "STUDENT": {
      "type": {
        "type": "string",
        "value": "STUDENT"
      },
      "PK": {
        "type": "string",
        "value": "TENANT#${tenantId}#STUDENT"
      },
      "SK": {
        "type": "string",
        "value": "${lastName}#${firstName}"
      },
      "studentId": {
        "type": "number"
      },
      "firstName": {
        "type": "string"
      },
      "lastName": {
        "type": "string"
      },
      "classOf": {
        "type": "number"
      },
      "tenantId": {
        "type": "string"
      }
    },
    "TEACHER": {
      "type": {
        "type": "string",
        "value": "TEACHER"
      },
      "PK": {
        "type": "string",
        "value": "TENANT#${tenantId}#TEACHER"
      },
      "SK": {
        "type": "string",
        "value": "${lastName}#${firstName}"
      },
      "employeeId": {
        "type": "string"
      },
      "firstName": {
        "type": "string"
      },
      "lastName": {
        "type": "string"
      },
      "department": {
        "type": "string"
      },
      "tenantId": {
        "type": "string"
      }
    }
  },
  "version": "0.1.0",
  "params": {
    "typeField": "type"
  },
  "format": "onetable:1.0.0",
  "queries": {}
};

relevant code in lambda:

async function addRecords(rec, model) {
    try {
        const res = await model.create(rec, { log: true });
        return res;
    } catch (err) {
        console.log("create item error:", err);
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

I’ve recently upgraded @aws-sdk/client-dynamodb to version 3.58.0 from 3.52.0 and that has fixed this issue for me.

I then went back and installed each version between 3.52.0 and 3.58.0 and found that it was resolved in 3.55.0. After looking through those commits I’m not too sure what changed to fix this issue.

edit: It’s definitely something to do with how they generate their errors though.