Skip to content

errors: improve ERR_INVALID_ARG_TYPE

Commit message 1: buffer: improve .from() error details

This makes sure the original input is passed to the error in case
no matching inputs are found. Instead of passing along all values,
only valid or possibliy valid values are passed through. That way
invalid values end up in the error case with the original input.

Commit message 2: errors: improve ERR_INVALID_ARG_TYPE

ERR_INVALID_ARG_TYPE is the most common error used throughout the
code base. This improves the error message by providing more details
to the user and by indicating more precisely which values are allowed
ones and which ones are not.

It adds the actual input to the error message in case it's a primitive.
If it's a class instance, it'll print the class name instead of
"object" and "falsy" or similar entries are not named "type" anymore.

The first commit is necessary to get the tests to pass. Otherwise the error would not log the actual input but the unboxed value.

I am not completely certain if we should handle Object special instead of just handling it as any other regular type. Any options on that?

// cc @trott

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading