{"record":{"id":"42c1096e06052be7","repo":"zed-industries/zed","slug":"could-not-get-screen-resolution-on-windows","errorCode":null,"errorMessage":"Could not get screen resolution on Windows","messagePattern":"Could not get screen resolution on Windows","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"script/zed-local","lineNumber":125,"sourceCode":"    const xrandrOutput = execSync('xrandr | grep \"\\\\*\" | cut -d\" \" -f4', {\n      encoding: \"utf8\",\n    }).trim();\n    [screenWidth, screenHeight] = xrandrOutput.split(\"x\").map(Number);\n  } catch (err) {\n    console.log(err);\n    throw new Error(\"Could not get screen resolution\");\n  }\n} else if (platform === \"win32\") {\n  // windows\n  try {\n    const resolutionOutput = execSync(\n      `powershell -Command \"& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Size}\"`,\n      { encoding: \"utf8\" },\n    ).trim();\n    [screenWidth, screenHeight] = resolutionOutput.match(/\\d+/g).map(Number);\n  } catch (err) {\n    console.log(err);\n    throw new Error(\"Could not get screen resolution on Windows\");\n  }\n}\n\nif (platform !== \"win32\") {\n  screenHeight -= titleBarHeight;\n}\n\nif (isTop) {\n  screenHeight = Math.floor(screenHeight / 2);\n}\n\n// Determine the window size for each instance\nlet rows;\nlet columns;\nswitch (instanceCount) {\n  case 1:\n    [rows, columns] = [1, 1];\n    break;","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/script/zed-local#L107-L143","documentation":"On Windows, script/zed-local asks PowerShell to load System.Windows.Forms and print PrimaryScreen.WorkingArea.Size, then extracts the numbers with /\\d+/g. The throw covers any failure in that pipeline: PowerShell execution policy or constrained language blocking Add-Type, a missing .NET/Windows Forms assembly, no interactive desktop — or output that doesn't match, making .match() return null so the .map() call throws inside the try.","triggerScenarios":"Running from a Windows service or session 0 with no interactive desktop; constrained language mode rejecting Add-Type; Server Core or trimmed .NET without Windows Forms; localized/unexpected output leaving no digits.","commonSituations":"CI agents running as services; hardened Windows boxes; Windows Server Core containers.","solutions":["Run the exact PowerShell one-liner in a terminal on the machine and inspect its output","Run the script from an interactive user session, not a service","If Add-Type is blocked, switch to another source, e.g. `wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution`","Null-check the regex match before .map()"],"exampleFix":"// before\n[screenWidth, screenHeight] = resolutionOutput.match(/\\d+/g).map(Number);\n\n// after\nconst digits = resolutionOutput.match(/\\d+/g);\nif (!digits || digits.length < 2) throw new Error(\"unexpected PowerShell output\");\n[screenWidth, screenHeight] = digits.map(Number);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  [screenWidth, screenHeight] = resolutionOutput.match(/\\d+/g).map(Number);\n} catch {\n  console.warn(\"Windows resolution probe failed; defaulting to 1920x1080\");\n  [screenWidth, screenHeight] = [1920, 1080];\n}","preventionTips":["Run the PowerShell probe interactively before automating it","Run window-layout scripts in interactive user sessions, not services","Null-check regex matches before calling .map() on them"],"tags":["windows","powershell","display","script"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}