{"record":{"id":"defc2cbef750e62f","repo":"BabylonJS/Babylon.js","slug":"service-contract-tostring-has-not-been-regi","errorCode":null,"errorMessage":"Service '${contract.toString()}' has not been registered in the '${this._friendlyName}' container.","messagePattern":"Service '(.+?)' has not been registered in the '(.+?)' container\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/sharedUiComponents/src/modularTool/modularity/serviceContainer.ts","lineNumber":148,"sourceCode":"            const instance = this._serviceInstances.get(definition);\r\n            if (!instance) {\r\n                throw new Error(`Service '${contract.toString()}' has not been instantiated in the '${this._friendlyName}' container.`);\r\n            }\r\n\r\n            let dependentDefinitions = this._serviceDependents.get(definition);\r\n            if (!dependentDefinitions) {\r\n                this._serviceDependents.set(definition, (dependentDefinitions = new Set()));\r\n            }\r\n            dependentDefinitions.add(consumer);\r\n\r\n            return instance;\r\n        }\r\n\r\n        if (this._parent) {\r\n            return this._parent._resolveDependency(contract, consumer);\r\n        }\r\n\r\n        throw new Error(`Service '${contract.toString()}' has not been registered in the '${this._friendlyName}' container.`);\r\n    }\r\n\r\n    /**\r\n     * Removes a consumer from the dependent set for a given contract, checking locally first then the parent chain.\r\n     * @param contract The contract identity.\r\n     * @param consumer The service definition to remove as a dependent.\r\n     */\r\n    private _removeDependentFromChain(contract: symbol, consumer: WeaklyTypedServiceDefinition): void {\r\n        const definition = this._serviceDefinitions.get(contract);\r\n        if (definition) {\r\n            const dependentDefinitions = this._serviceDependents.get(definition);\r\n            if (dependentDefinitions) {\r\n                dependentDefinitions.delete(consumer);\r\n                if (dependentDefinitions.size === 0) {\r\n                    this._serviceDependents.delete(definition);\r\n                }\r\n            }\r\n            return;\r","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/sharedUiComponents/src/modularTool/modularity/serviceContainer.ts#L130-L166","documentation":"_resolveDependency walked the local container's _serviceDefinitions, then the full parent chain via this._parent._resolveDependency, and found no registration at all for the requested contract. This is the terminal 'unknown contract' error, distinct from error 831 which fires when the contract is registered but not instantiated.","triggerScenarios":"Calling container.dependencies(definition) where definition.consumes contains a contract never registered (via produces) in this container or any ancestor; typo/mismatch of contract symbols; module providing the service not loaded.","commonSituations":"Forgetting to add the module/service that produces the dependency; using two different symbol instances for what the developer thinks is one contract (e.g. each file calling Symbol('foo') instead of importing a shared symbol); resolving a service in a child container whose parent chain doesn't host the producer.","solutions":["Add the service definition that produces the missing contract to the container (or its parent).","Import contract symbols from the single shared module that owns them; never create inline Symbol() contracts.","Check the container hierarchy: register the producer in a parent container if it must serve children.","Verify module load order so the producer is registered before consumers resolve dependencies."],"exampleFix":"// before\nconst FooContract = Symbol(\"Foo\"); // local symbol, not the registered one\n// after\nimport { FooContract } from \"./contracts\"; // shared symbol identity","handlingStrategy":"type-guard","validationCode":"// const contracts = new Set(loadedListedContracts);\n// if (!def.consumes.every((c) => contracts.has(c))) throw new Error(\"missing producer module\");","typeGuard":"function isRegistered(contract) {\n  return typeof contract === \"symbol\" && knownContracts.has(contract);\n}","tryCatchPattern":"// try {\n//   return container.dependencies(def);\n// } catch (e) {\n//   if (String(e.message).includes(\"has not been registered\")) {\n//     throw new Error(`Producer for ${e.message.match(/'(.*)'/)?.[1]} missing — did you load its module?`, { cause: e });\n//   }\n//   throw e;\n// }","preventionTips":["Register producing services before consumers resolve dependencies.","Import contract symbols from a single contracts module; never inline Symbol().","Verify child containers have the producer in a parent when needed."],"tags":["dependency-injection","missing-registration","modularity"],"backgroundTag":"service-not-registered","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}