{"record":{"id":"1320c6de5d9deb9d","repo":"Budibase/budibase","slug":"gotofunc-must-be-a-function-found-a-typeof-got","errorCode":null,"errorMessage":"gotoFunc must be a function, found a \"${typeof gotoFunc}\" instead","messagePattern":"gotoFunc must be a function, found a \"(.+?)\" instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/builder/src/stores/portal/navigation.ts","lineNumber":20,"sourceCode":"\ntype GotoFuncType = (path: string) => void\n\ninterface NavigationState {\n  initialisated: boolean\n  goto: GotoFuncType\n}\n\nclass NavigationStore extends BudiStore<NavigationState> {\n  constructor() {\n    super({\n      initialisated: false,\n      goto: undefined as any,\n    })\n  }\n\n  init(gotoFunc: GotoFuncType) {\n    if (typeof gotoFunc !== \"function\") {\n      throw new Error(\n        `gotoFunc must be a function, found a \"${typeof gotoFunc}\" instead`\n      )\n    }\n    this.set({\n      initialisated: true,\n      goto: gotoFunc,\n    })\n  }\n}\n\nexport const navigation = new NavigationStore()\n","sourceCodeStart":2,"sourceCodeEnd":32,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/builder/src/stores/portal/navigation.ts#L2-L32","documentation":"The navigation store is initialized with a SvelteKit-style goto function injected via init(gotoFunc). To fail fast on misconfiguration, init validates the argument is actually a function before storing it, throwing with the found typeof value otherwise.","triggerScenarios":"Calling init() with undefined/null (forgetting to pass goto), or passing a non-function such as a string path, an object, or a wrongly-imported module instead of the goto function.","commonSituations":"Bad import of goto (importing the module namespace rather than the function); calling init before SvelteKit context is available; refactor renamed/moved goto and the call site wasn't updated; testing setup not providing a mock goto.","solutions":["Pass the actual goto function, e.g. import { goto } from \"@svelterouter/kit\"-style source and call navigation.init(goto)","Check the import — ensure it destructures the function, not the module","Ensure init is called in the right lifecycle where goto is defined","In tests, provide a jest.fn() mock as the gotoFunc"],"exampleFix":"// before\nimport * as nav from \"$app/navigation\"\nnavigation.init(nav)\n// after\nimport { goto } from \"$app/navigation\"\nnavigation.init(goto)","handlingStrategy":"validation","validationCode":"if (typeof goto !== \"function\") {\n  throw new Error(\"navigation.init requires a goto function\")\n}\nnavigation.init(goto)","typeGuard":"const isGotoFunc = (f: unknown): f is GotoFuncType =>\n  typeof f === \"function\"","tryCatchPattern":"try {\n  navigation.init(goto)\n} catch (e) {\n  if (e.message.includes(\"gotoFunc must be a function\")) {\n    console.error(\"Check the goto import — expected the function, not the module\")\n  } else throw e\n}","preventionTips":["Import goto as a named function import, not a namespace import","Call init() at app bootstrap where goto is guaranteed defined","Add a unit test asserting navigation init receives a function","In tests, pass jest.fn() as the gotoFunc mock"],"tags":["builder","navigation","typeerror","validation","initialization"],"backgroundTag":"invalid-callback-argument","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}