{"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":"info","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/7e623aa83da3776faee50ca4ab9a6c40124acd95/compiler-core/src/io/memory.rs#L206-L242","documentation":"InMemoryFileSystem::write_bytes writes content into a freshly created Vec<u8> via io::Write::write and expects success (\"channel buffer write\"). Writing into a Vec is infallible in Rust — the std Write impl for Vec<u8> returns Ok unconditionally (allocation failure aborts the process rather than returning Err) — so this expect cannot fire through any public API. It is a defensive assertion whose appearance in a crash log would indicate memory corruption or a patched std, not a usage error.","triggerScenarios":"None reachable: there is no input to write_bytes that makes Vec's write return Err. OOM at this point aborts the allocator instead of reaching the expect.","commonSituations":"Realistically never seen; if a stack trace names it, suspect a fork-related allocator state bug or third-party allocator misuse in the same process, not gleam usage.","solutions":["Treat it as unreachable — no filesystem or project change affects it.","If you somehow hit it, reproduce under a default allocator (unset MALLOC_ARENA_MAX/LD_PRELOAD overrides) and check for OOM with dmesg.","For maintainers: replace `let _ = ... .expect(...)` with `let _ = io::Write::write_all(&mut file, content);` or a debug_assert to document infallibility."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Unreachable in practice; only relevant to long-running hosts that must\n// survive any panic:\nlet wrote = std::panic::catch_unwind(|| {\n    fs.write_bytes(&path, content) // InMemoryFileSystem::write_bytes\n});\nif wrote.is_err() {\n    tracing::error!(\"in-memory write panicked; memory state suspect — rebuilding fs\");\n    fs.reset();\n}","preventionTips":["No caller behavior influences this assertion; ignore it when designing usage.","If you maintain gleam_core, consider replacing the expect with write_all's infallible result to document that it cannot fail."],"tags":["panic","invariant","in-memory-fs","vec-write","unreachable","gleam-core"],"backgroundTag":"unreachable-assertion","analyzedSha":"7e623aa83da3776faee50ca4ab9a6c40124acd95","analyzedAt":"2026-08-17T00:07:02.091Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}