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

Improve error messages information (#70) #88

Merged
merged 3 commits into from
Jan 31, 2020

Conversation

emilioastarita
Copy link
Contributor

To address #70 handling composition of error messages with some helpers.

Example:

  class Ok {}

  @injectable()
  class C {
    constructor(public s: any) {}
  }

  @injectable()
  class B {
    constructor(public c: C) {}
  }

  @injectable()
  class A {
    constructor(public d: Ok, public b: B) {}
  }
container.resolve(A)

Will throw an exception like this:

Cannot inject the dependency "b" at position #1 of "A" constructor. Reason:
    Cannot inject the dependency "c" at position #0 of "B" constructor. Reason:
        Cannot inject the dependency "s" at position #0 of "C" constructor. Reason:
            TypeInfo not known for "Object"

expect(() => {
globalContainer.resolve(A);
}).toThrow(
/Cannot inject the dependency "b" at position #1 of "A" constructor. Reason:\s+Cannot inject the dependency "c" at position #0 of "B" constructor. Reason:\s+Cannot inject the dependency "s" at position #0 of "C" constructor. Reason:\s+TypeInfo not known for "Object"/
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Any way we can format this to be a little more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[/ /,/ /].map(x=>x.source).join() as in b11ea0c

makes readability any better?


return new ctor(...params);
}

private resolveParams<T>(context: ResolutionContext, ctor: constructor<T>) {
return (param: any, idx: number) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the specific types rather than any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I need to remove any from typeInfo map.

Something like this 144e07f it's ok?

@Xapphire13 Xapphire13 merged commit 75f769d into microsoft:master Jan 31, 2020
@emilioastarita emilioastarita deleted the fix_improve_exceptions#70 branch February 18, 2020 13:17
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.

2 participants