{"record":{"id":"3c81dac5c3d09f92","repo":"hcengineering/platform","slug":"descriptor-is-not-found-in-the-model","errorCode":null,"errorMessage":"Descriptor is not found in the model","messagePattern":"Descriptor is not found in the model","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/setting/src/utils.ts","lineNumber":41,"sourceCode":"  Space,\n  SpaceType,\n  TxOperations,\n  TypeAny as TypeAnyType,\n  getRoleAttributeLabel\n} from '@hcengineering/core'\nimport { getEmbeddedLabel, IntlString } from '@hcengineering/platform'\n\nimport setting from './index'\n\nexport async function createSpaceType<T extends SpaceType> (\n  client: TxOperations,\n  data: Omit<Data<T>, 'targetClass'>,\n  _id: Ref<T>,\n  _class: Ref<Class<T>> = core.class.SpaceType\n): Promise<Ref<T>> {\n  const descriptorObj = client.getModel().findObject(data.descriptor)\n  if (descriptorObj === undefined) {\n    throw new Error('Descriptor is not found in the model')\n  }\n\n  const baseClassClazz = client.getHierarchy().getClass(descriptorObj.baseClass)\n  // NOTE: it is important for this id to be consistent when re-creating the same\n  // space type with the same id as it will happen during every migration if type is created by the system\n  const spaceTypeMixinId = `${_id}:type:mixin` as Ref<Class<Space>>\n  await client.createDoc(\n    core.class.Mixin,\n    core.space.Model,\n    {\n      extends: descriptorObj.baseClass,\n      kind: ClassifierKind.MIXIN,\n      label: getEmbeddedLabel(data.name),\n      icon: baseClassClazz.icon\n    },\n    spaceTypeMixinId\n  )\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/setting/src/utils.ts#L23-L59","documentation":"createSpaceType creates a SpaceType object whose Data carries a descriptor reference. Before creating the object, the code looks the descriptor up in the client's model via findObject(data.descriptor); if no such model object exists it throws this error. It is a guard against creating space types whose descriptor was never registered in the model (e.g. by a plugin that isn't loaded).","triggerScenarios":"Calling createSpaceType with data.descriptor set to a Ref<SpaceTypeDescriptor> that is absent from the model — typically because the plugin defining that descriptor is not installed/enabled, the descriptor id is misspelled, or client.getModel() is built from an incomplete plugin list.","commonSituations":"Adding a custom space type after removing/renaming its descriptor plugin; using a descriptor from another product/plugin version; tests or migrations running with a trimmed plugin set that excludes the descriptor's plugin.","solutions":["Verify the descriptor plugin defining the Ref<SpaceTypeDescriptor> is included in the client's plugin configuration and loaded before createSpaceType is called","Print client.getModel().findObject(data.descriptor) and compare the id with the constant exported by the descriptor plugin to catch typos","If the descriptor was renamed/moved, update the caller to the new exported id instead of a string literal","Ensure the model is built with all required plugins (check the plugin list passed to the model builder in this app/test)"],"exampleFix":"// before\nawait createSpaceType(client, { descriptor: 'myapp:desc:Custom' as Ref<SpaceTypeDescriptor>, name: 'Custom', icon: ... })\n// after\nconst descriptor = myPlugin.descriptors.Custom // exported, type-checked id\nif (client.getModel().findObject(descriptor) === undefined) {\n  throw new Error('Plugin providing descriptor ' + descriptor + ' is not loaded')\n}\nawait createSpaceType(client, { descriptor, name: 'Custom', icon: ... })","handlingStrategy":"validation","validationCode":"function canCreateSpaceType<T extends SpaceType>(client: TxOperations, data: Data<T>): boolean {\n  return client.getModel().findObject(data.descriptor) !== undefined\n}\n// call before: if (!canCreateSpaceType(client, data)) throw new Error('Descriptor plugin not loaded')","typeGuard":"function isDescriptorInModel<T extends SpaceType>(client: TxOperations, ref: Ref<SpaceTypeDescriptor>): ref is Ref<SpaceTypeDescriptor> {\n  return client.getModel().findObject(ref) !== undefined\n}","tryCatchPattern":"try {\n  await createSpaceType(client, data, _id)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Descriptor is not found in the model') {\n    console.error('Descriptor missing from model:', data.descriptor, '- check plugin list')\n  }\n  throw err\n}","preventionTips":["Always reference descriptors via plugin-exported constants, never string literals","Keep the client's plugin list in sync with every space type you create","Add an early model assertion in tests for each descriptor used in fixtures"],"tags":["model","plugin-configuration","descriptor"],"backgroundTag":"model-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}