{"record":{"id":"51513551f753f79e","repo":"pbakaus/impeccable","slug":"sveltekit-live-adapter-requires-a-numeric-port-515135","errorCode":null,"errorMessage":"SvelteKit live adapter requires a numeric port","messagePattern":"SvelteKit live adapter requires a numeric port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"skill/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/skill/scripts/live/sveltekit-adapter.mjs#L46-L82","documentation":"Thrown by applySvelteKitLiveAdapter() in live/sveltekit-adapter.mjs when the 'port' argument fails Number.isFinite(Number(port)). The adapter needs a concrete numeric port to bake into the generated Svelte live root component (so the client knows where to poll); a non-numeric, NaN, or Infinity port cannot be embedded. The guard runs before any detection or file writes, so nothing is mutated on failure.","triggerScenarios":"applySvelteKitLiveAdapter({cwd, port, token}) is called with port = undefined, null, a non-numeric string like 'abc', NaN, or Infinity. Note Number('3000') would pass, but Number(undefined) = NaN fails.","commonSituations":"Port read from an env var that was unset (PORT -> undefined); CLI flag parsed as a flag presence boolean instead of a number; default port removed during a refactor; caller passed the raw string 'abc' by mistake; Infinity from a bad division.","solutions":["Pass a finite number: applySvelteKitLiveAdapter({cwd, port: 4321, token}).","Coerce and validate from env: const port = Number(process.env.PORT || 4321); guard with Number.isFinite before calling.","Ensure the CLI flag parser yields a number, not a string-only-when-set value."],"exampleFix":"// before\napplySvelteKitLiveAdapter({ cwd, port: process.env.PORT, token })\n// after\nconst port = Number(process.env.PORT || 4321)\napplySvelteKitLiveAdapter({ cwd, port, token })","handlingStrategy":"validation","validationCode":"const portNum = Number(port);\nif (!Number.isFinite(portNum)) throw new Error('port must be a finite number');\napplySvelteKitLiveAdapter({ cwd, port: portNum, token });","typeGuard":"function isFinitePort(v: unknown): v is number {\n  return Number.isFinite(typeof v === 'number' ? v : Number(v));\n}","tryCatchPattern":null,"preventionTips":["Centralize port resolution: const port = Number(process.env.PORT || DEFAULT_PORT); validate once.","Treat undefined/NaN/Infinity ports as a config-loading error, not a runtime one.","Type the adapter's port parameter as `number` (not number|string) to catch bad callers at compile time."],"tags":["sveltekit","adapter","port","validation","live"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}