{"record":{"id":"f169a212a3b6b1c5","repo":"gleam-lang/gleam","slug":"channel-buffer-write","errorCode":null,"errorMessage":"channel buffer write","messagePattern":"channel buffer write","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/io/memory.rs","lineNumber":224,"sourceCode":"                err: None,\n            });\n        }\n        let _ = files.remove(path);\n        Ok(())\n    }\n\n    fn write(&self, path: &Utf8Path, content: &str) -> Result<(), Error> {\n        self.write_bytes(path, content.as_bytes())\n    }\n\n    fn write_bytes(&self, path: &Utf8Path, content: &[u8]) -> Result<(), Error> {\n        // Ensure directories exist\n        if let Some(parent) = path.parent() {\n            self.mkdir(parent)?;\n        }\n\n        let mut file = InMemoryFile::default();\n        _ = io::Write::write(&mut file, content).expect(\"channel buffer write\");\n        _ = self\n            .files\n            .deref()\n            .borrow_mut()\n            .insert(path.to_path_buf(), file);\n        Ok(())\n    }\n\n    fn exists(&self, path: &Utf8Path) -> bool {\n        self.files.deref().borrow().contains_key(path)\n    }\n}\n\nimpl FileSystemReader for InMemoryFileSystem {\n    fn canonicalise(&self, path: &Utf8Path) -> Result<Utf8PathBuf, Error> {\n        Ok(path.to_path_buf())\n    }\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-core/src/io/memory.rs#L206-L242","documentation":"`InMemoryFileSystem::write_bytes` writes content into a fresh InMemoryFile through std::io::Write and expects success unconditionally ('channel buffer write'). The write target is an in-memory buffer, so failure indicates the underlying channel/buffer primitive is broken — an internal invariant, only reachable when the in-memory file abstraction's writer fails.","triggerScenarios":"Calling write_bytes, or its callers copy / write / to_in_memory_filesystem, when the InMemoryFile's internal buffer writer (implemented over a channel-like buffer) fails — practically a broken internal buffer, e.g. after a refactor replacing the buffer with a bounded channel.","commonSituations":"Gleam compiler runs writing modules to an in-memory FS (tests, LSP, export); would surface after changes to InMemoryFile internals rather than from user input.","solutions":["Inspect InMemoryFile's Write impl: it should never fail for in-memory buffers; restore an unbounded Vec/Cursor-based buffer.","If a channel is used, ensure the receiver stays alive and capacity is sufficient.","Propagate the io::Error with `?` instead of expect so failures are diagnosable."],"exampleFix":"// before\n_ = io::Write::write(&mut file, content).expect(\"channel buffer write\");\n// after\nio::Write::write(&mut file, content)?;","handlingStrategy":"validation","validationCode":"// ensure the in-memory writer cannot fail: InMemoryFile must wrap an unbounded buffer (Vec/Cursor), not a bounded channel\nassert!(matches!(file_kind, FileKind::UnboundedBuffer));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep InMemoryFile's Write impl infallible (in-memory buffer only).","Propagate io::Error with ? rather than expect for diagnosability.","Add a test writing large and empty payloads through write_bytes."],"tags":["rust","io","panic","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}