This page documents the 0.4 release candidates of @nexusdi/core. The newest on npm is 0.4.0-rc.1. The documentation for 0.3.2, the current release, is at nexus.js.org. Try the release candidate.
Error Codes Reference
Every error raised by NexusDI carries a stable code. By default, these errors provide a concise one-line message and a link to the specific documentation page for that code. When the @nexusdi/errors or @nexusdi/devtools plugins are registered, these codes are expanded into full human-readable messages with suggested fixes.
You can use the isNexusError(error, code) utility from @nexusdi/core to detect specific errors and narrow the error to its specific class. Check where the code arrives: most graph errors arrive inside the errors list of NEXUS_BLUEPRINT_INVALID, and an error raised while a provider is built arrives as the cause of NEXUS_PROVIDER_FAILED. How Each Code Arrives at the end of this page lists the way for every code.
A package that adds codes declares them in the NexusErrorByCode interface, and Writing NexusDI Plugins shows how.
Core Error Codes
These errors are raised by @nexusdi/core during graph validation or container resolution.
| Code | Class | Description |
|---|---|---|
NEXUS_BLUEPRINT_INVALID | BlueprintError | The module graph is invalid; see the errors array for specific issues. |
NEXUS_MISSING_PROVIDER | MissingProviderError | A dependency token has no visible provider. |
NEXUS_AMBIGUOUS_PROVIDER | AmbiguousProviderError | A module imports two or more modules that each export their own provider of the same token. |
NEXUS_DUPLICATE_PROVIDER | DuplicateProviderError | A single module defines the same provider multiple times. |
NEXUS_INVALID_EXPORT | InvalidExportError | A module attempts to export a token it does not provide or import. |
NEXUS_INVALID_PROVIDER | InvalidProviderError | A provider definition is malformed. |
NEXUS_INVALID_TOKEN | InvalidTokenError | A value is used as a token but is not a class or a Token instance, or a Token has an empty description. |
NEXUS_INVALID_MODULE | InvalidModuleError | A value used as a module is not a defineModule result or @Module class. |
NEXUS_MISSING_DEPS | MissingDepsError | A class with constructor parameters is missing its static deps list. |
NEXUS_CIRCULAR_DEPENDENCY | CircularDependencyError | A dependency loop was detected with no lazy() edge to break it. |
NEXUS_LIFETIME_VIOLATION | LifetimeError | A singleton depends on a scoped provider or on REQUEST (Captive Dependency). |
NEXUS_MODULE_IMPORT_CYCLE | ModuleImportCycleError | Two or more modules import each other in a loop. |
NEXUS_MODULE_OPTIONS_MISSING | ModuleOptionsError | A configurable module was imported without forRoot or forRootAsync. |
NEXUS_LOAD_GLOBAL_MODULE | LoadError | load() received a global module, or a module that imports a global module the graph lacks. |
NEXUS_INVALID_MODULE_OPTIONS | ModuleOptionsError | Module options failed the defined schema validation. |
NEXUS_PROVIDER_FAILED | ProviderError | A constructor, factory, onInit, or options validation threw an error during instantiation. |
NEXUS_NOT_READY | NotReadyError | A lazy() thunk was called before the target provider was initialized. |
NEXUS_ASYNC_TRANSIENT | AsyncTransientError | A transient factory returned a promise (transients must be synchronous). |
NEXUS_LAZY_ASYNC | LazyAsyncError | An eager: false provider, or its onInit, returned a promise on first use. |
NEXUS_NOT_VISIBLE | NotVisibleError | The token exists, but the requesting module cannot see it. |
NEXUS_SCOPE_REQUIRED | ScopeRequiredError | A scoped provider was requested from the root container. |
NEXUS_REQUEST_MISSING | RequestMissingError | createScope was called without a request object while scoped providers depend on REQUEST. |
NEXUS_LOADED_AFTER_SCOPE | LoadedAfterScopeError | A token was loaded into the root after the current scope was created. |
NEXUS_DISPOSED | DisposedError | The container or scope was used after being disposed. |
NEXUS_PLUGIN_INVALID | PluginError | A plugin passed to Nexus.create or Nexus.check is malformed. |
NEXUS_PLUGIN_VERSION | PluginError | A plugin declares a plugin API version this core does not support. |
NEXUS_PLUGIN_CONFLICT | PluginError | Two plugins rewrite the same module or provider. |
NEXUS_PLUGIN_FAILED | PluginError | A plugin hook threw or returned a value of the wrong type. |
Error Codes from Other Packages
These errors are raised by the other official NexusDI packages.
| Package | Code | Class | Description |
|---|---|---|---|
@nexusdi/interceptors | NEXUS_INTERCEPTOR_INVALID | InterceptorError | Interceptor definition or call is malformed. |
@nexusdi/interceptors | NEXUS_INTERCEPTOR_MISSING | InterceptorError | A declared interceptor was not registered in the plugin. |
@nexusdi/interceptors | NEXUS_INTERCEPTOR_LIFETIME | InterceptorError | An interceptor was marked as scoped or transient. |
@nexusdi/interceptors | NEXUS_INTERCEPTOR_NOT_READY | InterceptorError | Interceptor called before build or after disposal. |
@nexusdi/interceptors | NEXUS_INTERCEPTORS_SHARED | InterceptorError | An interceptors plugin object was passed to a second container while another container still holds it. |
@nexusdi/interceptors | NEXUS_INTERCEPTORS_UNCHECKED | InterceptorError | An instance was wrapped without being checked by the compiler. |
@nexusdi/testing | NEXUS_OVERRIDE_UNUSED | OverrideError | An override names a token that no provider binds, or a module the graph never imports. |
@nexusdi/testing | NEXUS_OVERRIDE_EXPORTS | OverrideError | A module stub doesn’t export everything the original did. |
@nexusdi/decorators | NEXUS_LEGACY_DECORATORS | LegacyDecoratorsError | A decorator ran under experimentalDecorators. |
@nexusdi/devtools | NEXUS_DEVTOOLS_UNREGISTERED | DevtoolsError | graph() called on a container without the devtools plugin. |
@nexusdi/devtools | NEXUS_DEVTOOLS_GRAPH_INVALID | DevtoolsError | The provided JSON is not a valid NexusGraph. |
@nexusdi/federation | NEXUS_CONTRACT_VERSION | ContractVersionError | A dependent needs a contract version its provider does not satisfy. |
How Each Code Arrives
isNexusError(e, code) on the top-level error matches only a code that arrives bare. A code found inside NEXUS_BLUEPRINT_INVALID sits in that error’s errors list, and a cause sits in the cause of NEXUS_PROVIDER_FAILED.
- Found inside
NEXUS_BLUEPRINT_INVALID:NEXUS_AMBIGUOUS_PROVIDER,NEXUS_DUPLICATE_PROVIDER,NEXUS_INVALID_EXPORT,NEXUS_INVALID_PROVIDER,NEXUS_MISSING_DEPS,NEXUS_CIRCULAR_DEPENDENCY,NEXUS_LIFETIME_VIOLATION,NEXUS_MODULE_IMPORT_CYCLE,NEXUS_MODULE_OPTIONS_MISSING,NEXUS_PLUGIN_INVALID,NEXUS_PLUGIN_VERSION,NEXUS_PLUGIN_CONFLICT,NEXUS_CONTRACT_VERSION,NEXUS_INTERCEPTOR_MISSING,NEXUS_INTERCEPTOR_LIFETIME,NEXUS_OVERRIDE_UNUSEDandNEXUS_OVERRIDE_EXPORTS. NEXUS_BLUEPRINT_INVALIDitself: thrown byNexus.create,Nexus.check,validate()andload(), witherrorslisting each problem.- Bare or inside, by caller:
get()andresolve()throwNEXUS_MISSING_PROVIDERbare for a token no module provides, andNexus.createandvalidate()report it insideNEXUS_BLUEPRINT_INVALID.NEXUS_INVALID_TOKENfollows the same split, andnew Token('')throws it bare too.load(),defineModule()and themoduleoption ofget()throwNEXUS_INVALID_MODULEbare, andNexus.createreports a badimportsentry insideNEXUS_BLUEPRINT_INVALID. - As the
causeofNEXUS_PROVIDER_FAILED:NEXUS_INVALID_MODULE_OPTIONS, aNEXUS_NOT_READYraised whileNexus.createbuilds, and any error a constructor, a factory or anonInitthrows. NEXUS_PLUGIN_FAILED: asetuphook and atokenKeyhook met in a lookup throw it bare, acompilehook reports it insideNEXUS_BLUEPRINT_INVALID, and aconstructhook makes it thecauseofNEXUS_PROVIDER_FAILED. Its owncauseholds the hook’s error.NEXUS_INTERCEPTOR_INVALID: the compile reports it insideNEXUS_BLUEPRINT_INVALID,@UseInterceptorsthrows it bare, and a build fault makes it thecauseofNEXUS_PROVIDER_FAILED. Itsreasonnames the rule.NEXUS_INTERCEPTORS_SHARED: reported insideNEXUS_BLUEPRINT_INVALID, or thecauseofNEXUS_PROVIDER_FAILEDwhen two creates overlap.- Thrown bare: every other code, from the call that hits it:
NEXUS_LOAD_GLOBAL_MODULEfromload(),NEXUS_NOT_VISIBLEandNEXUS_SCOPE_REQUIREDfrom a lookup,NEXUS_REQUEST_MISSINGfromcreateScope(),NEXUS_DISPOSEDafter disposal started, and the devtools and decorators codes from the call that raised them.