{"record":{"id":"ad4e31b51b1741af","repo":"hcengineering/platform","slug":"failed-to-find-target-project-type-typeid-ad4e31","errorCode":null,"errorMessage":"Failed to find target project type: ${typeId}","messagePattern":"Failed to find target project type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/recruit-resources/src/components/CreateVacancy.svelte","lineNumber":226,"sourceCode":"    }\n\n    await client.addCollection(tracker.class.Issue, space, parent, tracker.class.Issue, 'subIssues', data, resId)\n    if ((template.labels?.length ?? 0) > 0) {\n      const tagElements = await client.findAll(tags.class.TagElement, { _id: { $in: template.labels } })\n      for (const label of tagElements) {\n        await client.addCollection(tags.class.TagReference, space, resId, tracker.class.Issue, 'labels', {\n          title: label.title,\n          color: label.color,\n          tag: label._id\n        })\n      }\n    }\n    return resId\n  }\n\n  async function createVacancy (): Promise<void> {\n    if (typeId === undefined || typeType === undefined) {\n      throw Error(`Failed to find target project type: ${typeId}`)\n    }\n\n    const sequence = await client.findOne(core.class.Sequence, { attachedTo: recruit.class.Vacancy })\n    if (sequence === undefined) {\n      throw new Error('sequence object not found')\n    }\n\n    const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)\n    const data: Data<Vacancy> = {\n      ...vacancyData,\n      name: name.trim(),\n      description: template?.shortDescription ?? '',\n      fullDescription: null,\n      private: false,\n      archived: false,\n      number: (incResult as any).object.sequence,\n      company,\n      members,","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/recruit-resources/src/components/CreateVacancy.svelte#L208-L244","documentation":"This error is thrown by the createVacancy function in the CreateVacancy.svelte component of the Huly recruit plugin when the selected vacancy (project) type is missing at submit time. The component reads typeId from the shared $selectedTypeStore and derives typeType via $typeStore.get(typeId); if either is undefined, the vacancy cannot be typed/validated, so the function aborts before querying the Sequence and creating the Vacancy document. It is a guard against creating a Vacancy without a valid ProjectType reference.","triggerScenarios":"Clicking the create/save button in the vacancy creation popup while: (1) no project type has been selected yet (typeId === undefined because selectedTypeStore is empty), or (2) a typeId exists but is not present in typeStore (e.g. the type was deleted, filtered out by descriptors, or the typeStore query has not populated yet), so typeType === undefined.","commonSituations":"User opens the Create Vacancy dialog from a context that did not preselect a vacancy type; the ProjectType referenced by the store was deleted/archived by another user or removed after a workspace upgrade; a race where the typeStore live query has not yet loaded results before submit; embedding the component without initializing selectedTypeStore.","solutions":["Select a vacancy/project type in the creation dialog before submitting (the type selector must resolve a ProjectType).","Refresh the page/re-open the dialog so selectedTypeStore and typeStore re-sync with the server.","Verify the ProjectType still exists and is not hidden/archived: query task.class.ProjectType by the id shown in the error message.","If developing an integration, set $selectedTypeStore to a valid Ref<ProjectType> that is present in $typeStore before invoking createVacancy.","Check for version mismatches between task/task-resources plugins where typeStore population may have changed."],"exampleFix":"// before\nasync function createVacancy (): Promise<void> {\n  if (typeId === undefined || typeType === undefined) {\n    throw Error(`Failed to find target project type: ${typeId}`)\n  }\n  ...\n}\n// after\nasync function createVacancy (): Promise<void> {\n  if (typeId === undefined) {\n    // surface a UI validation message instead of throwing deep in the handler\n    showError(getEmbeddedLabel('Please select a vacancy type'))\n    return\n  }\n  const typeType = $typeStore.get(typeId)\n  if (typeType === undefined) {\n    showError(getEmbeddedLabel('Selected vacancy type is unavailable; please reselect it'))\n    return\n  }\n  ...\n}","handlingStrategy":"validation","validationCode":"// Run before calling createVacancy / enabling the submit button\nimport { get } from 'svelte/store'\nimport { selectedTypeStore, typeStore } from '@hcengineering/task-resources'\n\nfunction canCreateVacancy (): boolean {\n  const typeId = get(selectedTypeStore)\n  if (typeId === undefined) return false\n  return get(typeStore).get(typeId) !== undefined\n}","typeGuard":"function hasProjectType (\n  typeId: Ref<ProjectType> | undefined\n): typeId is Ref<ProjectType> & string {\n  return typeId !== undefined && $typeStore.get(typeId) !== undefined\n}","tryCatchPattern":"try {\n  await createVacancy()\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Failed to find target project type')) {\n    showPopup(MessageBox, {\n      label: getEmbeddedLabel('Please select a valid vacancy type before saving')\n    })\n  } else {\n    throw err\n  }\n}","preventionTips":["Disable the submit button until a project type is selected and resolvable in typeStore.","Keep selectedTypeStore initialized (e.g. default to the first active ProjectType) when opening the dialog.","Re-check that referenced ProjectTypes are not deleted/archived before listing them as selectable options.","Subscribe to the typeStore live query and clear an outdated selection if its type disappears.","In tests/integrations, seed a valid ProjectType and set selectedTypeStore before exercising creation flows."],"tags":["svelte","validation","project-type","recruit-plugin"],"backgroundTag":"missing-required-selection","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}