Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display full error object all the time regardless of argument position #958

Open
ggfrosch opened this issue Feb 23, 2024 · 1 comment
Open

Comments

@ggfrosch
Copy link

ggfrosch commented Feb 23, 2024

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.

args[0] = createDebug.coerce(args[0]);

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 #334. This open issue is also related, #711.

@hideishi-m
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants