Every error the container throws extends IocError, which extends Error. Each has its own class, so you can tell
them apart with instanceof, and its own name, so logs show which one it was. Messages name the tokens involved and,
where it applies, the path of services being resolved.
Error
Thrown when
Extra fields
Thrown by
ServiceNotFoundError
A required service, or a dependency of one, has no registration
token, key, path
getRequired*, resolving dependencies
CircularDependencyError
A cycle partner was used before its constructor finished
path
Resolution
ScopeError
Scoped service resolved from the root, or captured by a singleton (validateScopes)
none
Resolution
RegistrationError
A registration is invalid: too few dependency tokens, a non-class token with no implementation
none
add*, tryAdd*, replace
ValidationError
validateOnBuild found problems
errors: string[]
buildServiceProvider
DisposedError
A provider or scope was used after dispose()
none
get*, createScope
Errors thrown by your own code (a constructor, a factory, onInit, onDestroy) pass through unchanged.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
map(
functiontokenName(token:Token|undefined):string
Readable name of a token, for messages and diagnostics.
tokenName); // ['SignupService']: what was being resolved, outermost first
}
}
For keyed lookups, key holds the key and the message says with key '…'. getService and getKeyedService return
undefined for a missing top-level service instead of throwing, but a missing dependency of a registered service
still throws.
Thrown when a constructor uses a cycle partner that isn’t constructed yet. path
is the cycle, starting and ending with the service that was used too early: A → B → A.
Cannot use a disposed service provider or scope. Thrown by every get* method and createScope() after the
provider or scope was disposed, and on any scope after its root was disposed. A get* call that was still building
its service when the owner was disposed rejects with it too (the half-built service is disposed). dispose() itself
never throws it: later calls wait for the first disposal.
Resolves token, throwing ServiceNotFoundError if it is not registered.
getRequiredService(
classReportService
ReportService);
await
constreports:ReportService
reports.
ReportService.run(): Promise<void>
run();
} catch (
var error:unknown
error) {
if (
var error:unknown
errorinstanceof
classIocError
Base class of every error thrown by the container.
IocError) {
constlog: {
error(msg:string, err:unknown):void;
}
log.
functionerror(msg:string, err:unknown):void
error('container misconfigured',
var error:IocError
error); // a bug: alert, don't retry
}
throw
var error:unknown
error;
}
Errors raised while disposing are your services’ own errors, rethrown after every instance was disposed (an
AggregateError if more than one failed). See Lifecycle and disposal.