Encountering a Circular JSON stringify error on Nest.js without a useful stack trace

My application is being plagued by this critical error in production:

/usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:137
            ? `${this.colorize('Object:', logLevel)}\n${JSON.stringify(message, (key, value) => typeof value === 'bigint' ? value.toString() : value, 2)}\n`
                                                             ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ClientRequest'
    |     property 'socket' -> object with constructor 'Socket'
    --- property '_httpMessage' closes the circle
    at JSON.stringify (<anonymous>)
    at ConsoleLogger.stringifyMessage (/usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:137:62)
    at ConsoleLogger.formatMessage (/usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:130:29)
    at /usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:122:43
    at Array.forEach (<anonymous>)
    at ConsoleLogger.printMessages (/usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:117:18)
    at ConsoleLogger.error (/usr/src/app/node_modules/@nestjs/common/services/console-logger.service.js:44:14)
    at Logger.error (/usr/src/app/node_modules/@nestjs/common/services/logger.service.js:34:75)
    at Logger.descriptor.value (/usr/src/app/node_modules/@nestjs/common/services/logger.service.js:163:27)
    at ExceptionsHandler.handleUnknownError (/usr/src/app/node_modules/@nestjs/core/exceptions/base-exception-filter.js:54:43)

I am unable to replicate this issue during development and I am unsure of its root cause. Is there a way for me to trace back to where this error originated?

Even after running with DEBUG=*, I have not been able to pinpoint the exact source of the problem.

Based on my logs, I suspect that the error is occurring near these lines:

      this.logger.error(error.toString())
      throw new InternalServerErrorException(error.toString())

However, it appears that error.toString() returns [object Object], which although unhelpful, may not be incorrect.

Answer №1

It seems that an error, most likely an AxiosError or a similar HTTP client error, was not properly converted into an HttpException that Nest could handle. This may have caused Nest to attempt logging the error unsuccessfully. I recommend reviewing your usage of HttpService (or any other HTTP clients) for any potential issues. If you are still unable to identify the problem, consider utilizing a different logger that can manage circular JSON structures. Personally, I suggest using ogma, which is a tool I developed myself. Alternatively, you may also consider using pino.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating Immersive Web Pages

I am currently generating a large amount of data in HTML for periodic reporting purposes. The table consists of approximately 10,000 rows, totaling around 7MB in size. As a result, when users try to open it, the browser sometimes becomes unresponsive due t ...

Initiating an AJAX request to a JSP file

Attempting to make an ajax call to a jsp page as shown below: $(document).ready(function () { $('#photo').photobooth().on("image", function (event, dataUrl) { alert(dataUrl); //alert($('#mygroupuserid')); ...

Tips for positioning a delete button at the start of the row I am transferring to a different table

Displayed below are the contents of the initial table. <% for(int i = 0; i < result.length; i++) { %> <tr id='player-listing-<%=i %>'> <td style="vertical-align: top;"><button onclick="myFunction2(<%=i%> ...

Recurly.js version 3 with additional features

I'm currently exploring the functionality of addons in Recurly.js v3. For my form, I've linked a recurly.Pricing instance and added a checkbox for an optional addon: HTML <label for="plan-mobile" class="checkbox"> <input type="check ...

React-select: The default values will only be updated if they are initially set statically

Need help displaying a list of interests from backend data: profile : { interest: ["interest1", "interest2"], }; This is my implementation: import Creatable from "react-select/creatable"; class EditProfileInSettings exten ...

NodeJS: Extract images based on specified coordinates

Dealing with images that contain text can be a challenge, but by using tesseract and the imagemagick node module, I was able to extract the text successfully. The only issue I encountered was related to the image size. https://i.sstatic.net/XldZC.png For ...

Tips for locating a key within an object that houses a specific value in its array

In my Coffeescript code, I have created the following Javascript object: urlSets = a: [ 'url-a.com' 'url-b.com' 'url-c.com' ] b: [ 'url-d.com' 'url-e.com' 'url-f.com&a ...

Tips for including an authorization token in an HTTP request

I encountered a 401 unauthorized error when trying to access my REST endpoint, likely due to the security measures I have implemented. I suspect that there might be an issue with how I am handling the HTTP headers. The application utilizes a Spring Boot b ...

Directing a controller assignment in AngularJS 1.2 via a directive

Transitioning from angularJS 1.0 to 1.2 has presented a challenge for me when it comes to assigning a controller to a directive with a distinct scope, without explicitly defining the controller in my HTML using ng-controller. Let's look at this scena ...

Is your jQuery search scope correctly restricted?

Upon coming across this code snippet, I can't help but wonder if it's merely limiting the scope or selecting both elements simultaneously. container = jQuery("#test", parent.document); jQuery("param[name=scale]", another.object) Would anyone b ...

Transform the arrow function into a standard JavaScript function

Here is the React return code snippet I'm working with: return ( <div className='App'> <form onSubmit={this.submit.bind(this)}> <input value={this.state.input} onChange={(e) ...

What are some ways I can integrate my Json object into my IONIC app rather than relying on a hardcoded object?

I stumbled upon this IONIC app's services.js file and found an example using a hardcoded object called "employees." Instead of using the hardcoded object, I wanted to use a JSON file. However, my attempt to make this change did not work as expected. I ...

What is the best way to retrieve the content from the MongoDB Document in my GET request?

I encountered an issue while attempting to access the Question field within the JSON document body stored in a MongoDB database. Upon executing the GET request, the result displayed as follows: { "_readableState": { "objectMode": true, "highWaterM ...

Replace character within a table using jQuery

Below is the table content: <table> <tr> <td>"James"</td> <td>"do"</td> <td>"you</td> <td>"like</td> <td>"your life"</td> </tr> </table> <butt ...

The PUT rest service does not function in AngularJS version 1.0.8

I am facing an issue with my AngularJS application that has a CRUD Rest service. While the Create, Read, and Delete methods are functioning properly, the PUT method is not working. I have searched on Stackoverflow and found similar problems with accepted s ...

Sharing data between ejs and javascript files

When using Express, I have encountered an issue with passing a variable to an EJS file called "index.ejs". res.render("index",{passedUser:req.user.alias}) Although I am able to successfully print it using <%=passedUser%> in the EJS file, I require ...

Securing NextJS API Routes with API Key Authorization

I'm developing an app in NextJS 13 that utilizes API routes, and I aim to secure them against any unauthorized access from external functions. While my app integrates Auth0, there is no strict requirement for protection since unregistered individuals ...

Accessing a span element using an eval function

I have a function that accesses an input element and updates its value using the following line of code: eval('document.forms[0].telephone').value = $telephone[$i]; Now, I need to transfer this value to a span, but I'm having trouble refer ...

React DnD now enables dragging an entire list of cards instead of just a single card

Implementing react DnD in my react Project has been challenging. In the render method, I have defined a variable called Populate that generates a list of cards as shown below: render() { var isDragging = this.props.isDragging; var connect ...

Obtaining the following class name from elements

I am struggling with extracting classes from a block of HTML code: <div class="container"> <div class="item first">...</div> <div class="item second">...</div> <div class="item third">...</div> <div cla ...