Skip to content

Commit

Permalink
feat(di): extract debug messages to debug module
Browse files Browse the repository at this point in the history
  • Loading branch information
EisenbergEffect committed Apr 18, 2018
1 parent f773bfd commit 4bef6f8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
20 changes: 16 additions & 4 deletions scripts/app-bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/app-bundle.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/debug/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,17 @@ const codeLookup: Record<string, IMessageInfo> = {
4: {
type: MessageType.error,
message: 'Invalid animation direction.'
},
5: {
type: MessageType.error,
message: 'key/value cannot be null or undefined. Are you trying to inject/register something that doesn\'t exist with DI?'
},
6: {
type: MessageType.error,
message: 'Invalid resolver strategy specified.'
},
7: {
type: MessageType.error,
message: 'Constructor Parameter with index cannot be null or undefined. Are you trying to inject/register something that doesn\'t exist with DI?'
}
};
7 changes: 4 additions & 3 deletions src/runtime/di.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PLATFORM } from "./pal";
import { Injectable } from "./interfaces";
import { Reporter } from "./reporter";

type InterfaceSymbol = (target: Injectable, property: string, index: number) => any;

Expand Down Expand Up @@ -77,7 +78,7 @@ class Resolver implements IResolver, IRegistration {
case 5: //alias
return handler.get(this.state);
default:
throw new Error('Invalid strategy: ' + this.strategy);
throw Reporter.error(6, this.strategy);
}
}
}
Expand Down Expand Up @@ -306,7 +307,7 @@ export const Registration = {

function validateKey(key: any) {
if (key === null || key === undefined) {
throw new Error('key/value cannot be null or undefined. Are you trying to inject/register something that doesn\'t exist with DI?');
throw Reporter.error(5);
}
}

Expand Down Expand Up @@ -386,7 +387,7 @@ function invokeWithDynamicDependencies(container: IContainer, fn: Function, stat
lookup = staticDependencies[i];

if (lookup === null || lookup === undefined) {
throw new Error('Constructor Parameter with index ' + i + ' cannot be null or undefined. Are you trying to inject/register something that doesn\'t exist with DI?');
throw Reporter.error(7, `Index ${i}.`);
} else {
args[i] = container.get(lookup);
}
Expand Down

0 comments on commit 4bef6f8

Please sign in to comment.