{"record":{"id":"92a91f06990a7e39","repo":"zed-industries/zed","slug":"failed-to-add-stream-output","errorCode":null,"errorMessage":"failed to add stream output: {}","messagePattern":"failed to add stream output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_macos/src/screen_capture.rs","lineNumber":98,"sourceCode":"            configuration.setPixelFormat(0x42475241);\n            configuration.setWidth(metadata.resolution.width.0 as usize);\n            configuration.setHeight(metadata.resolution.height.0 as usize);\n\n            let stream = SCStream::initWithFilter_configuration_delegate(\n                SCStream::alloc(),\n                &filter,\n                &configuration,\n                None,\n            );\n            let output = StreamOutput::new(frame_callback);\n            let output_protocol = ProtocolObject::from_ref(&*output);\n\n            if let Err(error) = stream.addStreamOutput_type_sampleHandlerQueue_error(\n                output_protocol,\n                SCStreamOutputType::Screen,\n                None,\n            ) {\n                _ = sender.send(Err(anyhow!(\n                    \"failed to add stream output: {}\",\n                    error.localizedDescription()\n                )));\n\n                return receiver;\n            }\n\n            let state = Rc::new(RefCell::new(Some((sender, stream.clone(), output))));\n            let handler = RcBlock::new(move |error: *mut NSError| {\n                let Some((sender, stream, output)) = state.borrow_mut().take() else {\n                    return;\n                };\n                let result = if let Some(error) = error.as_ref() {\n                    Err(anyhow!(\n                        \"failed to start screen capture stream: {}\",\n                        error.localizedDescription()\n                    ))\n                } else {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_macos/src/screen_capture.rs#L80-L116","documentation":"macOS ScreenCaptureKit rejected the attempt to attach the screen output to an SCStream. When `addStreamOutput:type:sampleHandlerQueue:error:` fails, the capture stream cannot deliver frames, so the error (a localizedDescription from the ObjC layer) is surfaced as an anyhow error through the async channel.","triggerScenarios":"Calling `stream()` in gpui_macos's screen_capture when SCStream output setup fails — e.g. screen recording permission not granted, invalid stream configuration, or the stream was already torn down.","commonSituations":"First-run without Screen Recording permission in System Settings (TCC denial), running in environments without a display/entitlements, or macOS version where ScreenCaptureKit APIs changed.","solutions":["Grant Screen Recording permission to the app in System Settings > Privacy & Security > Screen Recording and relaunch","Check the localizedDescription in the message for the specific ScreenCaptureKit error","Verify SCStream configuration (width/height/pixel format) is valid for the target display","Ensure the app runs in an environment with a display and required entitlements"],"exampleFix":"// before\nif let Err(error) = stream.addStreamOutput_type_sampleHandlerQueue_error(...) { /* send error */ }\n// after\nif let Err(error) = stream.addStreamOutput_type_sampleHandlerQueue_error(...) {\n    _ = sender.send(Err(anyhow!(\"failed to add stream output: {}; check Screen Recording permission\", error.localizedDescription())));\n    return receiver;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check screen recording permission (macOS 15+)\nlet granted = CGPreflightScreenCaptureAccess();\nif !granted { panic!(\"Screen Recording permission required\"); }","typeGuard":"fn stream_output_added(result: &Result<Receiver, anyhow::Error>) -> bool { result.is_ok() }","tryCatchPattern":"let receiver = capture::stream(...);\nwhile let Some(event) = receiver.recv().await {\n    if let Err(e) = event {\n        if e.to_string().contains(\"failed to add stream output\") {\n            prompt_screen_recording_permission();\n            break;\n        }\n    }\n}","preventionTips":["Request Screen Recording permission before initializing capture","Test capture on the minimum supported macOS version for ScreenCaptureKit","Validate stream configuration dimensions against the display","Handle the empty frame stream gracefully when TCC denies access"],"tags":["macos","screencapturekit","permissions"],"backgroundTag":"permission-denied","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}