hcengineering/platform · error

lookup class does not provided for ${key}

Error message

lookup class does not provided for ${key}

What it means

getLookupClass resolves the target class for a $lookup key via getLookup(key, lookup, parent). If the lookup map has no entry for the key, the class is undefined and the function throws, since downstream lookup presenters need a concrete class.

Source

Thrown at plugins/view-resources/src/utils.ts:849

  } else {
    try {
      const attribute = client.getHierarchy().getAttribute(lookupClass, key.key)
      return attribute.label
    } catch {
      console.log('attribute not found for ' + key.key + ' in class ' + lookupClass)
      return getEmbeddedLabel(key.key)
    }
  }
}

export function getLookupClass<T extends Doc> (
  key: string,
  lookup: Lookup<T>,
  parent: Ref<Class<T>>
): [Ref<Class<Doc>>, Ref<Class<Doc>>, boolean] {
  const _class = getLookup(key, lookup, parent)
  if (_class === undefined) {
    throw new Error('lookup class does not provided for ' + key)
  }
  return _class
}

export function getLookupProperty (key: string): [string, string] {
  const parts = key.split('$lookup')
  const lastPart = parts[parts.length - 1]
  const split = lastPart.split('.').filter((p) => p.length > 0)
  const prev = split.shift() ?? ''
  const result = split.join('.')
  return [result, prev]
}

function getLookup (
  key: string,
  lookup: Lookup<any>,
  parent: Ref<Class<Doc>>
): [Ref<Class<Doc>>, Ref<Class<Doc>>, boolean] | undefined {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Ensure the Lookup object passed contains an entry for the key suffix
  2. Fix key spelling so getLookupProperty(key) matches the lookup property name
  3. Load lookup data (client lookup API) for the parent class before building the model

Example fix

// before
getLookupClass('attachedTo.$lookup', {}, taskClass) // throws
// after
const lookup: Lookup<Task> = { attachedTo: { _class: 'contact::Person' } }
getLookupClass('attachedTo.$lookup', lookup, taskClass)
Defensive patterns

Strategy: validation

Validate before calling

const suffix = key.split('$lookup')[1]?.split('.')[1] ?? key.split('$lookup')[1]
if (getLookup(key, lookup, parent) === undefined) {
  throw new Error('no lookup entry for key: ' + key)
}

Type guard

function hasLookupEntry<T extends Doc>(key: string, lookup: Lookup<T>, parent: Ref<Class<T>>): boolean {
  return getLookup(key, lookup, parent) !== undefined
}

Try / catch

try {
  const cls = getLookupClass(key, lookup, parent)
} catch (err) {
  if (String(err.message).startsWith('lookup class does not provided')) {
    const lookup = await client.loadLookup(parent, [key])
    return getLookupClass(key, lookup, parent)
  }
  throw err
}

Prevention

When it happens

Trigger: Calling model-building code with a lookup key whose suffix (after '$lookup') has no matching property in the Lookup object; passing an empty/wrong Lookup for the parent class.

Common situations: Lookup data not loaded for the class; key suffix typo (e.g. 'attachedTo' vs 'attachedTo.'); lookup defined on a different parent class in the hierarchy; nested $lookup keys whose intermediate class lookup is absent.

Related errors


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