{"record":{"id":"1a6569b307d71148","repo":"pbakaus/impeccable","slug":"sveltekit-live-adapter-requires-a-numeric-port","errorCode":null,"errorMessage":"SvelteKit live adapter requires a numeric port","messagePattern":"SvelteKit live adapter requires a numeric port","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugin/skills/impeccable/scripts/live/sveltekit-adapter.mjs","lineNumber":64,"sourceCode":"  if (!hasTemplateMarkers) return null;\n\n  const hasSvelteConfig = fs.existsSync(path.join(cwd, 'svelte.config.js'))\n    || fs.existsSync(path.join(cwd, 'svelte.config.mjs'))\n    || fs.existsSync(path.join(cwd, 'svelte.config.cjs'))\n    || fs.existsSync(path.join(cwd, 'svelte.config.ts'));\n  const hasKitPackage = packageHasSvelteKit(cwd);\n  if (!hasSvelteConfig && !hasKitPackage) return null;\n\n  return {\n    appHtml,\n    layoutFile: findSvelteKitLayout(cwd),\n    rootComponent: SVELTE_LIVE_ROOT_COMPONENT,\n  };\n}\n\nexport function applySvelteKitLiveAdapter({ cwd = process.cwd(), port, token, config = null } = {}) {\n  if (!Number.isFinite(Number(port))) {\n    throw new Error('SvelteKit live adapter requires a numeric port');\n  }\n  const detected = detectSvelteKitProject(cwd, config);\n  if (!detected) return null;\n\n  ensureSvelteLiveRootComponent(cwd, Number(port), token);\n\n  const layoutRel = detected.layoutFile;\n  const layoutAbs = path.join(cwd, layoutRel);\n  fs.mkdirSync(path.dirname(layoutAbs), { recursive: true });\n  const layoutExisted = fs.existsSync(layoutAbs);\n  const before = layoutExisted ? fs.readFileSync(layoutAbs, 'utf-8') : defaultSvelteLayout();\n  const after = patchSvelteLayout(before, { rev: svelteAdapterRev(token) });\n  fs.writeFileSync(layoutAbs, after, 'utf-8');\n\n  return {\n    file: layoutRel,\n    adapter: 'sveltekit',\n    inserted: after !== before || !layoutExisted,","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/pbakaus/impeccable/blob/d14711ae3d1a1dd62dee61a358d27f107c51ccd0/plugin/skills/impeccable/scripts/live/sveltekit-adapter.mjs#L46-L82","documentation":"Thrown by applySvelteKitLiveAdapter when the port argument cannot be coerced to a finite number. The adapter writes the live mount component with the port baked in, so a non-numeric port would produce a broken component; the guard fails fast before touching any files.","triggerScenarios":"Calling applySvelteKitLiveAdapter({ port: undefined }), port: null, port: 'abc', or port: NaN. Number(port) is non-finite and the throw fires before detectSvelteKitProject.","commonSituations":"The boot did not parse a --port flag, an env var (PORT) was unset and flowed through as undefined, or a string port was passed uncoerced.","solutions":["Pass a numeric port: applySvelteKitLiveAdapter({ port: 4321 }).","Coerce from env: port: Number(process.env.IMPECCABLE_PORT) and validate it is finite before calling.","Ensure the boot flow assigns a concrete port before invoking the adapter."],"exampleFix":"// before\napplySvelteKitLiveAdapter({ cwd, port: undefined, token });\n\n// after\nconst port = Number(process.env.IMPECCABLE_PORT ?? 4321);\nif (!Number.isFinite(port)) throw new Error('port must be numeric');\napplySvelteKitLiveAdapter({ cwd, port, token });","handlingStrategy":"validation","validationCode":"function isValidPort(port) {\n  const n = Number(port);\n  return Number.isFinite(n) && n > 0 && n < 65536;\n}","typeGuard":"function isNumericPort(port) {\n  return Number.isFinite(Number(port));\n}","tryCatchPattern":"try {\n  applySvelteKitLiveAdapter({ cwd, port, token });\n} catch (err) {\n  if (err.message === 'SvelteKit live adapter requires a numeric port') {\n    port = 4321; // default and retry\n    applySvelteKitLiveAdapter({ cwd, port, token });\n  } else throw err;\n}","preventionTips":["Always coerce port via Number() and validate with Number.isFinite before calling the adapter.","Default the port in the boot flow so undefined never reaches the adapter.","Reject ports outside 1-65535 upstream for a clearer error."],"tags":["validation","svelte","sveltekit","impeccable-live","port"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}