gulpjs / plugin-error

Error handling for vinyl plugins. Just an abstraction of what's in gulp-util with minor reformatting.
MIT License
19 stars 13 forks source link

PluginError toString output #14

Open demurgos opened 6 years ago

demurgos commented 6 years ago

Imported from https://github.com/gulpjs/gulp-util/issues/74.

Currently console.log'ing the error outputs way too much:

{ [Error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]
  message: 'error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-ruby-sass',
  __safety: { toString: [Function] } }

It should only output:

[Error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]

Or even better:

[gulp-ruby-sass error: error main.scss (Line 7: Invalid CSS after "@import ": expected file to import (string or url()), was "blah;")]

Just define a .toString method for it outputting what we want.

re https://github.com/yeoman/generator-gulp-webapp/pull/242#issuecomment-67011031

/cc @sindresorhus @contra

fasttime commented 1 year ago

Just noting that console.log does not use toString to format its output, e.g.

console.log({ foo: 'bar', toString: () => 'nice text' });

outputs

{ foo: 'bar', toString: () => 'nice text' }

If the goal is to change the output of console.log, as the ticket description implies, one has to use util.inspect.custom:

const util = require('util');

console.log({ foo: 'bar', [util.inspect.custom]: () => 'nice text' });

outputs:

nice text

Regardless, it would be nice to remove some unnecessary information from the output of toString, like domainEmitter [object Object].

phated commented 1 year ago

@fasttime We already made attempts to improve this in https://github.com/gulpjs/plugin-error/commit/932946a72ed8911aaa362ce09ef9d14931a97542 - if we missed a property, I'm happy to add it to the list of exclusions and release as a bug fix. Want to PR?

fasttime commented 1 year ago

@phated Okay, I made a PR: #26.