{"record":{"id":"39dd2c159319b773","repo":"hcengineering/platform","slug":"createdocumenttemplate-ops-commit-failed","errorCode":null,"errorMessage":"createDocumentTemplate: ops.commit() failed","messagePattern":"createDocumentTemplate: ops\\.commit\\(\\) failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/controlled-documents/src/docutils.ts","lineNumber":344,"sourceCode":"      ...spec,\n      code,\n      seqNumber,\n      category,\n      prefix: TEMPLATE_PREFIX,\n      author,\n      owner: author,\n      content: spec.content ?? null\n    },\n    templateId\n  )\n  await ops.createMixin(templateId, documents.class.Document, space, _mixin, {\n    sequence: 0,\n    docPrefix: prefix\n  })\n  const commit = await ops.commit()\n\n  if (!commit.result) {\n    console.warn('createDocumentTemplate: ops.commit() failed', {\n      _class,\n      space,\n      _mixin,\n      project,\n      parent,\n      templateId,\n      prefix,\n      category,\n      author\n    })\n  }\n\n  return { seqNumber, success: commit.result }\n}\n\nexport async function createDocumentTemplateMetadata (\n  client: TxOperations,\n  _class: Ref<Class<Document>>,","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/controlled-documents/src/docutils.ts#L326-L362","documentation":"createDocumentTemplate assembles an Ops transaction creating a document template object (_class/_mixin with sequence 0 and the given docPrefix) and commits it. A falsy commit.result means the template was not created; the failure is logged as a warning with all construction parameters.","triggerScenarios":"Calling createDocumentTemplate with an invalid _class/_mixin combination, a space or project that does not resolve, a parent reference that fails validation, or a templateId that collides with an existing object during commit.","commonSituations":"Misconfigured mixin registration for the template class; creating templates in a space that was archived; duplicate template creation due to double-submit in the UI.","solutions":["Review the logged fields (_class, space, _mixin, project, parent, templateId) to identify the invalid reference.","Verify the mixin is registered and the _class is a valid template class for this space.","Ensure the templateId does not already exist (check for double-submit and deduplicate).","Retry template creation after confirming parent/project exist."],"exampleFix":"// before\nawait createDocumentTemplate(client, { _class, space, _mixin, project, parent, templateId, prefix })\n// after\nconst existing = await client.findOne(_class, { _id: templateId })\nif (existing !== undefined) throw new Error('template already exists')\nawait createDocumentTemplate(client, { _class, space, _mixin, project, parent, templateId, prefix })","handlingStrategy":"validation","validationCode":"if (await client.findOne(_class, { _id: templateId }) !== undefined) throw new Error('template already exists')","typeGuard":"function isCommitOk(c: any): c is { result: true } {\n  return c != null && c.result === true\n}","tryCatchPattern":"const commit = await createDocumentTemplate(client, args)\nif (!commit.success) {\n  throw new Error(`template creation failed for ${args.templateId}`)\n}","preventionTips":["Guard against double-submitting template creation in the UI.","Ensure the _mixin is registered before creating templates of that class.","Do not create templates in archived or deleted spaces."],"tags":["controlled-documents","commit-failure","template"],"backgroundTag":"transaction-commit-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}