{"record":{"id":"0e8a47f90434141f","repo":"immich-app/immich","slug":"failed-to-call-host-function-string-name-re","errorCode":null,"errorMessage":"Failed to call host function \"${String(name)}\", received ${result.status} - ${JSON.stringify(result.message)}","messagePattern":"Failed to call host function \"(.+?)\", received (.+?) - (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-sdk/src/host-functions.ts","lineNumber":71,"sourceCode":"] as const;\n\nexport const hostFunctions = (authToken: string) => {\n  const host = Host.getFunctions();\n  type HostFunctionName = keyof typeof host;\n\n  const call = <T, R>(name: HostFunctionName, authToken: string, args: T) => {\n    const pointer1 = Memory.fromString(JSON.stringify({ authToken, args }));\n    const fn = host[name];\n    const handler = Memory.find(fn(pointer1.offset));\n\n    try {\n      const result = JSON.parse(handler.readString()) as HostFunctionResult<R>;\n\n      if (result.success) {\n        return result.response;\n      }\n\n      throw new Error(\n        `Failed to call host function \"${String(name)}\", received ${result.status} - ${JSON.stringify(result.message)}`,\n      );\n    } finally {\n      handler.free();\n      pointer1.free();\n    }\n  };\n\n  return {\n    // album\n    searchAlbums: (dto: AlbumSearchDto) =>\n      call<[AlbumSearchDto], AlbumResponseDto[]>('searchAlbums', authToken, [\n        dto,\n      ]),\n    createAlbum: (dto: CreateAlbumDto) =>\n      call<[CreateAlbumDto], AlbumResponseDto>('createAlbum', authToken, [dto]),\n    addAssetsToAlbum: (albumId: string, assetIds: string[]) =>\n      call<[string, BulkIdsDto], BulkIdResponseDto[]>(","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/packages/plugin-sdk/src/host-functions.ts#L53-L89","documentation":"In the Immich plugin SDK, plugin code invokes a host function (exposed by the app runtime over WASM) and the host returns a serialized HostFunctionResult with success=false. The SDK throws with the function name plus the host-provided status and message, telling the plugin author the host-side call failed (not the SDK call mechanics).","triggerScenarios":"Calling any hostFunctions.* method from a plugin when the host rejects it: e.g. requesting a function not exposed by the current host version, passing arguments the host validates and rejects, or the host lacking permission/context for the operation.","commonSituations":"Running a plugin built against a newer SDK on an older Immich host, calling user-scoped functions without the required user session, or passing malformed DTOs to host functions like asset search.","solutions":["Read result.status/message in the error text; it names the host-side cause (missing permission, bad argument, unknown function).","Align plugin SDK version with the host Immich version and rebuild the plugin.","Validate the arguments/DTO passed to the host function against the SDK types.","Confirm the plugin runs in the intended context (user session/admin) that grants the function."],"exampleFix":"// before\nawait hostFunctions.getAssetById(id); // throws if host rejects\n// after\ntry {\n  await hostFunctions.getAssetById(id);\n} catch (e) {\n  log(`host call failed: ${e.message}`); // surface status + message from host\n}","handlingStrategy":"try-catch","validationCode":"// pin matching SDK + host versions at build time\nassert(pluginSdkVersion === hostImmichVersion, 'SDK/host version mismatch');","typeGuard":null,"tryCatchPattern":"try {\n  const res = await hostFunctions.someCall(args);\n} catch (e) {\n  const { status, message } = parseHostError(e.message);\n  if (status === 403) requestPermissionAndRetry();\n  else if (status === 404) disableFeature();\n  else throw e;\n}","preventionTips":["Keep plugin SDK version aligned with the target Immich host version","Validate DTO arguments with SDK types before host calls","Check required permissions/session context for the function used"],"tags":["wasm","plugin-sdk","host-function","rpc"],"backgroundTag":"upstream-api-error","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}