Skip to content

[dove][package error] Creating an error with a null err breaks #2789

Closed

Description

@mdartic

I'm migrating the feathers-authentication-management package to dove, and I encounter an error in the... error package :-).

We have a call to BadRequest with potentially no error message in first param (see https://github.com/feathersjs-ecosystem/feathers-authentication-management/blob/master/src/methods/check-unique.ts#L74-L77).

In crow implementation, if we make the call

const err = new BadRequest(null, data)
// this will equivalent to
const err = FeathersError(null, 'BadRequest', 400, 'bad-request', data);

err will be like

{
  type: 'FeathersError',
  name: 'BadRequest',
  message: 'Error', // by default, with null value in first param, the "Error" string is set
  code: 400,
  className: 'bad-request', 
  ...
}

In dove implementation, with the same call - the BadRequest one,
this will break at #L35 as typeof null === 'object' is true.
Code will try to destructure null in { message, errors, ...rest }.

Another interesting thing is that constructor of errors like, eg, BadRequest takes 2 optional params message?: ErrorMessage, data?: any, but the FeathersError constructor want mandatory params : err and _data aren't optional.
This use case allow feathers-authentication-management to still create BadRequest errors with an err null.

Is this use case still accepted ?
Could we fix the previous implementation ?
I fix temporary the package by updating the #L36 :

  const { message, errors, ...rest } = typeof err === 'object' && err !== null ? err : _data;

If needed, I can submit a PR with fix on typing (FeathersError constructor with err: ErrorMessage | null) and tests proving new BadRequest(null, ...) work.

Activity

  1. daffl commented on Oct 12, 2022

    @daffl
    Member

    Thanks for the detailed error report. This should be fixed via #2776

  2. mdartic commented on Oct 12, 2022

    @mdartic
    ContributorAuthor

    Thanks !

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions