hcengineering/platform · error · Error

class not found: ${_class}

Error message

class not found: ${_class}

What it means

getClass looks up a Class object in the loaded model's classifier map and throws 'class not found' when the ref is absent OR when it resolves to an interface (which is not a concrete class). It is the strict counterpart of findClass, used pervasively (spaceClass, value, ancestor, clazz, etc.).

Source

Thrown at foundations/core/packages/core/src/hierarchy.ts:198

  }

  isMixin (_class: Ref<Class<Doc>>): boolean {
    const data = this.classifiers.get(_class)
    return data !== undefined && this._isMixin(data)
  }

  getAncestors (_class: Ref<Classifier>): Ref<Classifier>[] {
    const result = this.ancestors.get(_class)
    if (result === undefined) {
      throw new Error('ancestors not found: ' + _class)
    }
    return result
  }

  getClass<T extends Obj = Obj>(_class: Ref<Class<T>>): Class<T> {
    const data = this.classifiers.get(_class)
    if (data === undefined || this.isInterface(data)) {
      throw new Error('class not found: ' + _class)
    }
    return data
  }

  findClass<T extends Obj = Obj>(_class: Ref<Class<T>>): Class<T> | undefined {
    const data = this.classifiers.get(_class)
    if (data === undefined || this.isInterface(data)) {
      return undefined
    }
    return data
  }

  hasClass<T extends Obj = Obj>(_class: Ref<Class<T>>): boolean {
    const data = this.classifiers.get(_class)

    return !(data === undefined || this.isInterface(data))
  }

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Use findClass when absence is expected; reserve getClass for refs that must exist.
  2. Confirm the ref points to a Class, not an Interface (interfaces are rejected here).
  3. Ensure the owning plugin's model is loaded/translated before querying.
  4. Align plugin versions between client and server so the class definition exists.
  5. Catch the error to detect stale/unknown refs and skip or re-hydrate the object.

Example fix

// before
const clazz = hierarchy.getClass(doc.class as Ref<Class<Doc>>)
// after
const data = hierarchy.findClass(doc.class as Ref<Class<Doc>>)
if (data === undefined) {
  throw new Error(`Class ${doc.class} missing from loaded model`)
}
const clazz = data
Defensive patterns

Strategy: type-guard

Validate before calling

const data = hierarchy.findClass(_class)
if (data === undefined) throw new Error(`Ref ${_class} not in model`)
if (hierarchy.isInterface(data)) throw new Error(`${_class} is an interface, not a class`)

Type guard

function isConcreteClass(h: Hierarchy, ref: Ref<Classifier>): ref is Ref<Class<Obj>> {
  const data = h.findClass(ref)
  return data !== undefined && !h.isInterface(data)
}

Try / catch

let clazz: Class<Obj>
try {
  clazz = hierarchy.getClass(_class)
} catch (err) {
  if (err.message.startsWith('class not found')) {
    throw new Error(`Class ${_class} missing — check plugin/model load`)
  }
  throw err
}

Prevention

When it happens

Trigger: getClass called with: a Ref<Class> never registered in the model; a ref to an Interface instead of a Class; queries executed before model load; refs from plugins not present in the deployment.

Common situations: Passing an interface ref (e.g. from core.interfaces) where a class is required; typos in class refs; plugin not installed/translated so its classes never enter the model; version mismatch where a class was renamed/removed.

Related errors


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