debug icon indicating copy to clipboard operation
debug copied to clipboard

Display full error object all the time regardless of argument position

Open ggfrosch opened this issue 1 year ago • 1 comments

A quick explanation:

var debug = require('debug')('http');

const error = new Error('hi');
error.info= { display: 'me' };
debug(error) ;
debug('', error); // this will output info object 

This is not mentioned in the readme and I had to hunt the reason for this. If an error is the first argument, it will be coerced.

https://github.com/debug-js/debug/blob/f66cb2d9f729e1a592e72d3698e3b75329d75a25/src/common.js#L82

At the very least, this behavior should be documented in the readme.

An option could be added to change this behavior. At first, the option could default to the current behavior and then the default behavior can be changed after a reasonable period.

This issue is related to https://github.com/debug-js/debug/issues/334. This open issue is also related, https://github.com/debug-js/debug/issues/711.

ggfrosch avatar Feb 23 '24 21:02 ggfrosch

I agree to this idea.

I also had hard time to investigate why debug(error) only shows stack traces, but no other visible properties unless debug is "wrapped" with other object such as { error: error } .

My interim solution is to override createDebug.coerce() to return the value as it is.

const debug = require("debug");
debug.coerce = (val) => val;
const debugError = debug('http');

const error = new Error('hi');
error.info= { display: 'me' };
debugError(error);  // now full object will be displayed.

I wish if I could use debug without such tweaking.

hideishi-m avatar Oct 25 '24 13:10 hideishi-m