{"record":{"id":"9b94c1b23c58327b","repo":"emberjs/ember.js","slug":"expected-a-context-object-to-be-passed-as-the-firs","errorCode":null,"errorMessage":"Expected a context object to be passed as the first parameter to invokeHelper, got ${context}","messagePattern":"Expected a context object to be passed as the first parameter to invokeHelper, got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@glimmer/runtime/lib/helpers/invoke.ts","lineNumber":54,"sourceCode":"\n  get named() {\n    return getArgs(this).named || EMPTY_NAMED;\n  }\n\n  get positional() {\n    return getArgs(this).positional || EMPTY_POSITIONAL;\n  }\n}\n\n////////////\n\nexport function invokeHelper(\n  context: object,\n  definition: object,\n  computeArgs?: (context: object) => Partial<Arguments>\n): Cache {\n  if (DEBUG && (typeof context !== 'object' || context === null)) {\n    throw new Error(\n      `Expected a context object to be passed as the first parameter to invokeHelper, got ${context}`\n    );\n  }\n\n  const owner = getOwner(context);\n\n  const internalManager = getInternalHelperManager(definition);\n\n  if (DEBUG && typeof internalManager === 'function') {\n    throw new Error(\n      'Found a helper manager, but it was an internal built-in helper manager. `invokeHelper` does not support internal helpers yet.'\n    );\n  }\n\n  const manager = (internalManager as InternalHelperManager<object>).getDelegateFor(owner);\n  let args = new SimpleArgsProxy(context, computeArgs);\n  let bucket = manager.createHelper(definition, args);\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@glimmer/runtime/lib/helpers/invoke.ts#L36-L72","documentation":"`invokeHelper` creates a helper instance cache for programmatic use (e.g. in modifiers or custom runtime code) and requires a context object as its first argument, from which the owner is resolved via getOwner. This debug assertion throws when the first parameter is not an object (missing, undefined, a primitive, or null), meaning no owner can be retrieved to construct the helper.","triggerScenarios":"Calling `invokeHelper(null, definition)` or `invokeHelper(undefined, definition)`; passing a primitive like a string/number as context; forgetting to thread a component/owner object into a modifier that calls invokeHelper.","commonSituations":"Custom modifiers or low-level integrations building helpers manually; refactors that drop the context parameter; running code before a component instance is available; using invokeHelper outside a component-based context where the passed \"context\" is a plain primitive.","solutions":["Pass a real object as the first argument, typically the component/owner instance: `invokeHelper(this, SomeHelper, () => ({ positional: [args] }))`","Check that the context variable is defined and non-null at the call site","Ensure invokeHelper is used within a runtime context where an owner can be resolved from the context object"],"exampleFix":"// before\nconst helper = invokeHelper(undefined, MyHelper);\n// after\nclass MyModifier extends Modifier {\n  modify(el, _, { positional }) {\n    const helper = invokeHelper(this, MyHelper, () => ({ positional }));\n  }\n}","handlingStrategy":"type-guard","validationCode":"function safeInvokeHelper(context, definition, computeArgs) { if (context === null || typeof context !== 'object') throw new TypeError('invokeHelper first arg must be a non-null object'); return invokeHelper(context, definition, computeArgs); }","typeGuard":"function isInvokeContext(c: unknown): c is object { return typeof c === 'object' && c !== null; }","tryCatchPattern":"try { cache = invokeHelper(ctx, def, argFn); } catch (e) { if (String(e.message).includes('invokeHelper')) { console.error('invalid context for invokeHelper:', e.message); } else { throw e; } }","preventionTips":["Always pass the component/owner instance as context","Check context is a non-null object before calling","Do not call invokeHelper before the component instance exists","Keep computeArgs callbacks returning a valid Partial<Arguments>"],"tags":["glimmer","runtime","invokehelper","type-error","owner"],"backgroundTag":"missing-context-object","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}