hcengineering/platform · error

createDocumentTemplate: ops.commit() failed

Error message

createDocumentTemplate: ops.commit() failed

What it means

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.

Source

Thrown at plugins/controlled-documents/src/docutils.ts:344

      ...spec,
      code,
      seqNumber,
      category,
      prefix: TEMPLATE_PREFIX,
      author,
      owner: author,
      content: spec.content ?? null
    },
    templateId
  )
  await ops.createMixin(templateId, documents.class.Document, space, _mixin, {
    sequence: 0,
    docPrefix: prefix
  })
  const commit = await ops.commit()

  if (!commit.result) {
    console.warn('createDocumentTemplate: ops.commit() failed', {
      _class,
      space,
      _mixin,
      project,
      parent,
      templateId,
      prefix,
      category,
      author
    })
  }

  return { seqNumber, success: commit.result }
}

export async function createDocumentTemplateMetadata (
  client: TxOperations,
  _class: Ref<Class<Document>>,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Review the logged fields (_class, space, _mixin, project, parent, templateId) to identify the invalid reference.
  2. Verify the mixin is registered and the _class is a valid template class for this space.
  3. Ensure the templateId does not already exist (check for double-submit and deduplicate).
  4. Retry template creation after confirming parent/project exist.

Example fix

// before
await createDocumentTemplate(client, { _class, space, _mixin, project, parent, templateId, prefix })
// after
const existing = await client.findOne(_class, { _id: templateId })
if (existing !== undefined) throw new Error('template already exists')
await createDocumentTemplate(client, { _class, space, _mixin, project, parent, templateId, prefix })
Defensive patterns

Strategy: validation

Validate before calling

if (await client.findOne(_class, { _id: templateId }) !== undefined) throw new Error('template already exists')

Type guard

function isCommitOk(c: any): c is { result: true } {
  return c != null && c.result === true
}

Try / catch

const commit = await createDocumentTemplate(client, args)
if (!commit.success) {
  throw new Error(`template creation failed for ${args.templateId}`)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/39dd2c159319b773. Report an issue: GitHub.