hcengineering/platform · error

Training request #${ref} not found

Error message

Training request #${ref} not found

What it means

The training request title provider looks up a TrainingRequest by reference and throws when the findOne query returns undefined. Title providers must return a display string, so a missing request is an unrecoverable lookup failure. It indicates the referenced request no longer exists or the ref is wrong.

Source

Thrown at plugins/training-resources/src/functions/trainingRequestObjectTitleProvider.ts:39

export async function trainingRequestObjectTitleProvider (
  client: Client,
  ref: Ref<TrainingRequest>,
  doc?: TrainingRequest
): Promise<string> {
  const request = await client.findOne<TrainingRequest>(
    training.class.TrainingRequest,
    {
      _id: ref
    },
    {
      lookup: {
        attachedTo: training.class.Training
      }
    }
  )
  if (request === undefined) {
    throw new Error(`Training request #${ref} not found`)
  }
  const trainingObject = request.$lookup?.attachedTo
  if (trainingObject === undefined) {
    throw new Error(`Training #${request.attachedTo} not found`)
  }

  const revisionLabel = client.getHierarchy().getAttribute(trainingObject._class, 'revision').label
  const revisionString = await translate(revisionLabel, {}, getCurrentLanguage())
  return `${trainingObject.code} • ${trainingObject.title} • ${revisionString} ${trainingObject.revision}`
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Confirm the TrainingRequest with that ref still exists in the current workspace.
  2. Purge or repair stale references (notifications, changelogs) that point to deleted requests.
  3. Verify the lookup query includes the correct attachedTo class and space.
  4. Add existence checks before resolving titles for potentially deleted objects.

Example fix

// before
const title = await trainingRequestObjectTitleProvider(client, ref)
// after
const exists = await client.findOne(training.class.TrainingRequest, { _id: ref })
const title = exists ? await trainingRequestObjectTitleProvider(client, ref) : 'deleted request'
Defensive patterns

Strategy: type-guard

Validate before calling

const req = await client.findOne(training.class.TrainingRequest, { _id: ref })
if (req === undefined) return 'request unavailable'

Type guard

function requestExists(r: TrainingRequest | undefined): r is TrainingRequest { return r !== undefined }

Try / catch

try { return await titleProvider(client, ref) } catch { return `#${ref} (deleted)` }

Prevention

When it happens

Trigger: Rendering a title for TrainingRequest #ref where no document matches the lookup (attachedTo: training.class.Training), e.g. the request was deleted or the ref points to a non-existent id.

Common situations: Stale references after request deletion; notifications/changelog entries pointing at removed requests; querying the wrong workspace/project; ids copied between environments.

Related errors


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