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

feat(dev): better DI error messages for instantiation #1917

Merged
merged 1 commit into from
Mar 3, 2024

Conversation

bigopon
Copy link
Member

@bigopon bigopon commented Mar 2, 2024

📖 Description

Currently, when there is an error during the instantiation of a class, there is not enough information what went wrong. This is quite an issue once there are multiple changes being added in at once, like in a dependency upgrade.

Enhance the DEV mode error message by catching the dependency resolution error while instantiate, so that there will be more information for debugging.

Examples

  1. for the following code with inject:

    export class App {
      static inject = [class Abc {
        constructor() {
          throw new Error('testing testing');
        }
      }]
    }

    The error messages logged will look like this:

    image

  2. For the following code with resolve:

    export class App {
      abc = resolve(class Abc {
        constructor() {
          throw new Error('testing testing');
        }
      });
    }

    The error messages logged will look like this
    image

🎫 Issues

Resolves #913

cc @xenoterracide @Sayan751 @fkleuver

Copy link

codecov bot commented Mar 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.52%. Comparing base (32f00ed) to head (0120642).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1917      +/-   ##
==========================================
+ Coverage   88.47%   88.52%   +0.04%     
==========================================
  Files         260      260              
  Lines       22843    22843              
  Branches     5258     5258              
==========================================
+ Hits        20211    20222      +11     
+ Misses       2632     2621      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bigopon bigopon merged commit 2fca6ea into master Mar 3, 2024
26 checks passed
@bigopon bigopon deleted the feat/dev-di-messages branch March 3, 2024 09:27
Copy link
Member

@Sayan751 Sayan751 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bigopon for this nice change! I think most of the devs won't use the dev/builds by default. Hence, I think we should have the same information also for non-dev builds.

@bigopon
Copy link
Member Author

bigopon commented Mar 3, 2024

@Sayan751 if a serious app was to be public, it needs to be first developed in dev mode before a prod build, and thus, error like this will be prominent and get ridden of, so this scenario we don't need these errors in prod mode.
If an app was a non serious one, it can just use dev build for both development and production, and will still be fine.
I think we shouldn't carry this experience enhancement into our prod build.

@Sayan751
Copy link
Member

Sayan751 commented Mar 3, 2024

In that case, I think we should have "recipe" documentation on how to enable the dev mode. As it might not always be straightforward.

@bigopon
Copy link
Member Author

bigopon commented Mar 3, 2024

@Sayan751 thanks, and agree, Ive been thinking of an faq doc or something to describe these.

AureliaEffect pushed a commit that referenced this pull request Mar 15, 2024
2.0.0-beta.13 (2024-03-15)

**BREAKING CHANGE:**

* **event:** no longer call prevent default by default (#1926) ([f71e9e7](f71e9e7))
* **exports:** no longer re-export fetch client package (#1926) ([f71e9e7](f71e9e7))

**Features:**

* **process-content:** ability to add template information to a data object (#1925) ([2a4c436](2a4c436))
* **template-controller:** ability to have a container per factory (#1924) ([6727b56](6727b56))
* **convention:** add import as support (#1920) ([7a15551](7a15551))
* **resources:** api to register resources with alias key ([7a15551](7a15551))
* **dev:** better DI error messages for instantiation (#1917) ([2fca6ea](2fca6ea))

**Bug Fixes:**

* **router-lite:** dont register config ([f71e9e7](f71e9e7))
* **di:** cache factory on singleton resolution ([dc22fb7](dc22fb7))

**Refactorings:**

* **router:** (DEV) dont swallow instantiation error details ([deee8e6](deee8e6))
* **compiler:** remove special treatment for au slot ([2a4c436](2a4c436))
* **kernel:** smaller di files, assert text options, more au slot tests ([deee8e6](deee8e6))
* **runtime:** move constructor registration into controller ([7a15551](7a15551))
* **resource:** cleanup registration, APIs (#1918) ([dc22fb7](dc22fb7))
* **resources:** cleanup util fn, move to kernel package ([dc22fb7](dc22fb7))
* **resources:** move find to corresponding resource kind ([dc22fb7](dc22fb7))
* **di:** add registrable, remove unecessary infra for attr pattern ([dc22fb7](dc22fb7))
* **resource:** remove resource protocol, simplify resource metadata ([dc22fb7](dc22fb7))

**Docs:**

* **docs:** add key documentation for the repeater (#1921) ([c3d0ed3](c3d0ed3))
* **docs:** add documentation for event preventDefault breaking change (#1926) ([f71e9e7](f71e9e7))
@tareqimbasher
Copy link
Sponsor

@bigopon @Sayan751 This is a great addition but can't find any documentation on how to use dev mode. Can you provide some info on how I would go about that? Thank you!

@Sayan751
Copy link
Member

@tareqimbasher Here is an example how to use development builds: https://github.com/aurelia/new/blob/master/webpack/webpack.config.js#L120

@tareqimbasher
Copy link
Sponsor

@Sayan751 Great, thank you! Plugged in those aliases and its working.

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

Successfully merging this pull request may close these issues.

DI tracing - tell me what thing is trying to be injected into
3 participants