{"record":{"id":"1e74e8393fef406b","repo":"hcengineering/platform","slug":"please-select-initial-state-space-1e74e8","errorCode":null,"errorMessage":"Please select initial state:${_space}","messagePattern":"Please select initial state:(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/recruit-resources/src/components/MoveApplication.svelte","lineNumber":62,"sourceCode":"  import VacancyCard from './VacancyCard.svelte'\n  import VacancyOrgPresenter from './VacancyOrgPresenter.svelte'\n\n  export let selected: Applicant[]\n\n  const status: Status = OK\n\n  let _space = selected[0]?.space\n\n  const dispatch = createEventDispatcher()\n  const client = getClient()\n\n  export function canClose (): boolean {\n    return true\n  }\n\n  async function updateApplication () {\n    if (selectedState === undefined) {\n      throw new Error(`Please select initial state:${_space}`)\n    }\n    if (selectedState === undefined) {\n      throw new Error(`create application: state not found space:${_space}`)\n    }\n\n    const op = client.apply(undefined, 'application.states')\n\n    for (const a of selected) {\n      await moveToSpace(op, a, _space, { status: selectedState._id })\n    }\n    await op.commit()\n    dispatch('close')\n  }\n\n  let states: Array<{ id: number | string, color: number, label: string }> = []\n  let selectedState: TaskStatus | undefined\n  let rawStates: TaskStatus[] = []\n  const spaceQuery = createQuery()","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/recruit-resources/src/components/MoveApplication.svelte#L44-L80","documentation":"Thrown in MoveApplication.svelte when `selectedState` is undefined while moving an application to another space. The application must be assigned a state in the destination space, so the update aborts. Notably the function duplicates the same check twice; the second (unreachable) copy shows the intended 'state not found space:' message.","triggerScenarios":"User confirms the move dialog without choosing a target state; the destination space's states have not loaded or the space has no states configured so the selector remains empty.","commonSituations":"Destination vacancy/project without a set-up state machine; UI permitting submit on an empty selector; async state loading that has not resolved when the user clicks move.","solutions":["Select a state for the destination space before confirming the move","Ensure the target space has states configured/inherited from its project type","Disable the move button until selectedState is defined","Remove the duplicated check and catch the error to show a friendly prompt"],"exampleFix":"// before\nif (selectedState === undefined) {\n  throw new Error(`Please select initial state:${_space}`)\n}\nif (selectedState === undefined) {\n  throw new Error(`create application: state not found space:${_space}`)\n}\n// after\nif (selectedState === undefined) {\n  ui.notify(`Please select a state in ${_space} before moving`) \n  return\n}","handlingStrategy":"validation","validationCode":"if (selectedState === undefined) {\n  ui.notify(`Select a state in ${_space} before moving`) \n  return\n}\nawait updateApplication()","typeGuard":"function hasState (state: Ref<DomainState> | undefined): state is Ref<DomainState> {\n  return state !== undefined\n}","tryCatchPattern":"try {\n  await updateApplication()\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Please select initial state')) {\n    ui.notify('Choose a destination state to complete the move.')\n  } else throw err\n}","preventionTips":["Preselect a default state when opening the move dialog","Load destination space states before enabling confirm","Remove the duplicated selectedState check","Validate states whenever the target space changes"],"tags":["validation","missing-selection","state-machine"],"backgroundTag":"required-field-missing","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}