GithubHelp home page GithubHelp logo

flex-development / exceptions Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 4.97 MB

๐Ÿšง Custom error classes and utilities

Home Page: https://github.com/flex-development/exceptions

License: BSD 3-Clause "New" or "Revised" License

JavaScript 33.16% TypeScript 65.10% Shell 1.18% Ruby 0.38% Handlebars 0.17%
error-handling exceptions typescript

exceptions's People

Contributors

dependabot[bot] avatar unicornware avatar

Watchers

 avatar  avatar  avatar

exceptions's Issues

๐Ÿ› DeprecationWarning: Invalid 'main' field

Description

Using @flex-development/[email protected] in a Next.js project yields a DeprecationWarning:

info  - Creating an optimized production build...
(node:13935) [DEP0128] DeprecationWarning: Invalid 'main' field in '/Users/lex/Projects/FLDV/TEMPLATES/unistack/apps/web/node_modules/@flex-development/exceptions/package.json' of 'dist/index.js'. Please either fix that or report it to the module author
(Use `node --trace-deprecation ...` to show where the warning was created)

Steps to reproduce

  1. Create a Next.js project using [email protected]
  2. Install @flex-development/[email protected]
  3. Run next build
  4. See error

Expected behavior

A DeprecationWarning should not be thrown when using @flex-development/[email protected].

Relevant screenshots

N/A

Environment

Possible solution

The create-dist-package-json script used in @flex-development/exceptions contains the logic to update the package main field, but it seems it didn't work properly for v2.0.1. Additionally, since first releasing this project, our organization's package build, publish, and release workflows have undergone major changes. Those updates should be implemented in this repository.

Additional context

N/A

๐Ÿ‘€ Extend AggregateError

Describe the ideal solution or feature request

Node.js 15 updates the JavaScript engine to V8 8.6, which introduces the AggregateError class. As explained in the MDN docs, the AggregateError class groups several errors together:

The AggregateError object represents an error when several errors need to be wrapped in a single error. It is thrown when
multiple errors need to be reported by an operation

Despite the current type definition for Exception#errors allowing for more than array types, a more appropriate superclass for Exception would be AggregateError seeing that the property name indicates a group of errors.

This update would introduce several changes:

  • Refactor data transfer objects, interfaces, and type definitions

    /**
     * `Exception` data transfer object.
     *
     * @template T - Aggregated error type
     */
    export interface ExceptionDataDTO<T extends any = any> { ... }
    /**
     * JSON representation of an `Exception`.
     *
     * @template T - Aggregated error type
     */
    export interface ExceptionJSON<T extends any = any> { ... }
    /**
     * Exception#errors` shape.
     *
     * @template T - Aggregated error type
     */
    export type ExceptionErrors<T extends any = any> = Array<T>
  • Convert Exception into a generic and extend AggregateError

    /**
     * @template T - Aggregated error type
     *
     * @extends {AggregateError}
     */
    class Exception<T extends any = any> extends AggregateError { ... }

Note:

  • Refactoring ExceptionErrors is a breaking change
  • Node.js users must be using at least Node.js 15
  • Some users may need to polyfill the AggregateError class

Additionally, we should take this opportunity to enforce (mostly) proper Error subclassing. Aside from the class naming rule, all rules defined by eslint-plugin-unicorn rule unicorn/custom-error-definition should be followed. This also requires a breaking change - we need to rename ExceptionName as well as update all associated naming logic.

Impact, usage, and difficulty

User goals Usage frequency Difficulty scale
ie. What the user wants to accomplish ie. Daily, weekly, monthly, yearly ie. Scale of 1 - 5
refactor Exception to extend AggregateError instead of Error daily 1
refactor Exception to extend AggregateError instead of Error daily 1

How does this tie into our current product?

The original intention for this package was to implement a consistent Error subclass API as well as provide stricter type definitions than the @feathers/errors library. This update makes existing type definitions stricter and subsequently improves consistency when working with Exception class objects. If this request is implemented, users no longer have to check if Exception#errors is an array, object, or string. The property will always be an array, and therefore users can always use Array APIs when interfacing with Exception#errors property.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.