{"record":{"id":"b2901d1e1be553da","repo":"eythaann/Seelen-UI","slug":"current-monitor-not-found-b2901d","errorCode":null,"errorMessage":"Current monitor not found","messagePattern":"Current monitor not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/ui/svelte/weg/state/system.svelte.ts","lineNumber":7,"sourceCode":"import { SeelenWegSide } from \"@seelen-ui/lib/types\";\nimport { currentMonitorId, monitors, mousePos } from \"./getters.svelte.ts\";\n\nconst _currentMonitor = $derived.by(() => {\n  const monitor = monitors.value.find((m) => m.id === currentMonitorId);\n  if (!monitor) {\n    throw new Error(\"Current monitor not found\");\n  }\n  return monitor;\n});\n\nconst _mouseAtEdge = $derived.by((): SeelenWegSide | null => {\n  const box = _currentMonitor.rect;\n  const x = mousePos.value.x;\n  const y = mousePos.value.y;\n\n  if (x < box.left || x > box.right || y < box.top || y > box.bottom) {\n    return null;\n  }\n\n  if (y === box.top) return SeelenWegSide.Top;\n  if (x === box.left) return SeelenWegSide.Left;\n  if (y === box.bottom - 1) return SeelenWegSide.Bottom;\n  if (x === box.right - 1) return SeelenWegSide.Right;\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/src/ui/svelte/weg/state/system.svelte.ts#L1-L25","documentation":"Same family as the fancy-toolbar error: the SeelenWeg (dock) widget derives the current monitor from `monitors.value.find((m) => m.id === currentMonitorId)` and throws `Current monitor not found` when absent. The dock's geometry (`_mouseAtEdge`, positioning) depends on this monitor rect, so the derivation failure breaks the whole widget state.","triggerScenarios":"Initial load before `monitors` is populated; `currentMonitorId` stale after unplugging the monitor the dock lives on; monitor id changed after sleep/resume or graphics-driver reset.","commonSituations":"Dock webview launching at startup racing the first monitor list event; docking/undocking a laptop; changing primary display in Windows settings while SeelenWeg is attached to it.","solutions":["Add a fallback to the primary/first monitor or return a safe default instead of throwing inside the derivation.","Await signal initialization (`await monitors.init()`) before mounting the dock UI.","Handle monitor hot-plug events so `currentMonitorId` is re-resolved (or the widget re-created) when the old id disappears."],"exampleFix":"// before\nif (!monitor) throw new Error(\"Current monitor not found\");\n// after\nif (!monitor) return monitors.value[0] ?? null;","handlingStrategy":"fallback","validationCode":"const current = monitors.value.find((m) => m.id === currentMonitorId) ?? monitors.value[0];\nif (!current) return; // no monitors yet — skip dock geometry","typeGuard":"function getMonitor(id: string) {\n  return monitors.value.find((m) => m.id === id) ?? monitors.value[0] ?? null;\n}","tryCatchPattern":"try {\n  layoutDock(_currentMonitor.rect);\n} catch (e) {\n  if ((e as Error).message === \"Current monitor not found\") hideDock();\n  else throw e;\n}","preventionTips":["Initialize monitor signals before the dock's first reactive evaluation.","React to MonitorsChanged to refresh currentMonitorId after hot-plug/resume.","Prefer returning a fallback monitor over throwing inside $derived.by."],"tags":["monitors","race-condition","svelte","dock"],"backgroundTag":"monitor-not-found","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}