Our label service is a Node.js application that books parcels with four carriers. When a carrier refuses a booking, the service catches the error from the HTTP client and logs it with one line we had written years earlier: console.error('carrier rejected label', err.response.data). A counter of rejections per carrier feeds a dashboard, and that counter is what started this.
In September rejections from one carrier rose from a handful a day to about two hundred, all on its Saturday service. Each morning the on-call engineer opened the logs, found the rejections, and read this:
carrier rejected label { fault: { errors: [ [Object] ] } }
The carrier's actual reason was inside that [Object]. Node formats objects passed to console.log and console.error with util.inspect, and its default depth is two. The response body was the top level, fault was one level down, errors was two, and each error object sat at the third level, so it was printed as a placeholder. The line looked like a log of the failure. It was a log of the shape of the failure.
Because the line said nothing, the rejections were filed as the carrier being unreliable, and the parcels were rebooked by hand on the weekday service. That went on for three weeks. Then someone replayed one booking with curl and read the full body: the carrier had withdrawn Saturday delivery for a list of rural postcodes and published the change in a partner bulletin nobody on our side received. Our own code had been told which field and why, every time.
The service now logs through pino, which writes one JSON object per line and serialises the whole response body, with a size cap rather than a depth limit. The carrier's error code is a label on the rejection counter, so the dashboard shows the reason instead of only the volume, and a new code appearing for the first time raises a ticket. We also searched every service for console calls that log an object, and found nineteen.
A log line that names the failure without its reason feels complete when you read it. It is the most expensive kind, because it stops people looking.
– Sergey Shinder
Top comments (1)
Node.js
util.inspectdefaults todepth: 2, which is why the carrier error at the third nesting level prints as[Object]. Pass{depth: null}to see the full structure:This is a long-standing default (since Node 0.10) and affects both
console.logandconsole.errorsince they delegate toutil.inspect.