{"record":{"id":"934863e37fc95c1f","repo":"hcengineering/platform","slug":"failed-to-create-test-plan","errorCode":null,"errorMessage":"Failed to create test plan","messagePattern":"Failed to create test plan","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/test-management-resources/src/components/test-plan/NewTestPlanPanel.svelte","lineNumber":97,"sourceCode":"          testSuite: testCase.attachedTo,\n          assignee: defaultAssignee,\n          collection: 'items'\n        }\n\n        return await applyOp.addCollection(\n          testManagement.class.TestPlanItem,\n          space,\n          id,\n          testManagement.class.TestPlan,\n          'items',\n          testPlanItemData,\n          testPlanItemId\n        )\n      })\n      await Promise.all(createPromises)\n      const opResult = await applyOp.commit()\n      if (!opResult.result) {\n        throw new Error('Failed to create test plan')\n      } else {\n        Analytics.handleEvent(TestManagementEvents.TestPlanCreated, { id })\n        dispatch('close')\n      }\n    } catch (err: any) {\n      console.error(err)\n      Analytics.handleError(err)\n    }\n  }\n\n  onMount(() => dispatch('open', { ignoreKeys: [] }))\n</script>\n\n{#if object}\n  <ActionContext context={{ mode: 'editor' }} />\n  <Panel\n    object={newDoc}\n    isHeader={false}","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/test-management-resources/src/components/test-plan/NewTestPlanPanel.svelte#L79-L115","documentation":"NewTestPlanPanel.svelte builds a batched client.apply() transaction creating the TestPlan doc, description attachments, and one TestPlanItem per selected test case. After applyOp.commit(), the server returns an operation result; if opResult.result is falsy the commit failed server-side (validation, permissions, conflict, or partial op rejection) and the code throws this Error. The catch block logs and reports to Analytics; the panel stays open and no TestPlanCreated event is dispatched.","triggerScenarios":"applyOp.commit() resolves but opResult.result is undefined/false — e.g. the server rejected one of the createDoc/addCollection ops (invalid space, missing testManagement mixin, permission denied), a conflicting concurrent edit to the same doc, or the transaction partially failing server-side.","commonSituations":"Workspace storage adapter failure or transient DB issue during commit; user's account lacks create permission on TestPlan/TestPlanItem in the test project space; stale client data after another user modified the same plan; misconfigured test-management plugin so the server cannot resolve the class.","solutions":["Inspect the commit rejection details: log the full opResult (console.error(opResult)) before throwing to see which op and why it failed.","Verify the current account has permission to create TestPlan and TestPlanItem docs in the target test project space.","Refresh the client and retry — a stale hierarchy/concurrent edit can cause the server to reject the tx.","Check server logs for the corresponding tx rejection (storage adapter or DB errors) around the time of the failure.","As a UX fallback, surface an error message to the user in the catch block instead of only console.error/Analytics."],"exampleFix":"// before\nconst opResult = await applyOp.commit()\nif (!opResult.result) {\n  throw new Error('Failed to create test plan')\n}\n// after\nconst opResult = await applyOp.commit()\nif (!opResult.result) {\n  console.error('TestPlan commit rejected', opResult)\n  throw new Error(`Failed to create test plan: ${JSON.stringify(opResult.error ?? opResult)}`)\n}","handlingStrategy":"try-catch","validationCode":"const client = getClient()\nconst canCreate = client.getHierarchy()\n  .getAttribute(testManagement.class.TestPlan, 'name') !== undefined\nif (space === undefined || !canCreate) {\n  console.error('Cannot create test plan: invalid space or model')\n}","typeGuard":"function isCommitSuccess(opResult: { result?: boolean }): opResult is { result: true } {\n  return opResult.result === true\n}","tryCatchPattern":"try {\n  const opResult = await applyOp.commit()\n  if (!opResult.result) {\n    throw new Error(`Test plan commit rejected: ${JSON.stringify(opResult.error ?? opResult)}`)\n  }\n} catch (err: any) {\n  console.error(err)\n  Analytics.handleError(err)\n  showErrorToast('Failed to create test plan. Please retry.')\n}","preventionTips":["Always check opResult.result after apply().commit() and log the full result for diagnostics.","Verify create permissions on TestPlan/TestPlanItem for the current account before opening the panel.","Refresh client data before long-lived panels commit to reduce concurrent-modification rejections.","Show user-facing feedback in the catch block instead of only console.error/Analytics."],"tags":["test-management","transaction-commit","server-rejection"],"backgroundTag":"transaction-commit-rejected","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}