{"record":{"id":"ecadee7d9dfe5847","repo":"atuinsh/atuin","slug":"writing-to-a-string-cannot-fail","errorCode":null,"errorMessage":"writing to a String cannot fail","messagePattern":"writing to a String cannot fail","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/atuin-common/src/ansi.rs","lineNumber":59,"sourceCode":"                if !std::mem::take(&mut first) {\n                    // Trim the end of the line that was pushed in the previous iteration, and add\n                    // the newline that we didn't push.\n                    plain_contents.trim_end_matches_in_place([' ', '\\t']);\n                    plain_contents.push('\\n');\n                }\n                plain_contents.push_str(plain_line);\n            }\n        }\n    }\n\n    impl vt100::Callbacks for Capture {\n        fn on_scroll(&mut self, contents: vt100::capture::RowContents<'_>, alternate_screen: bool) {\n            if alternate_screen {\n                return;\n            }\n            contents\n                .write_formatted_basic(&mut self.buffer, &mut self.state)\n                .expect(\"writing to a String cannot fail\");\n            push_formatted(&mut self.plain_contents, &self.buffer);\n            self.buffer.clear();\n        }\n    }\n\n    if input.is_empty() {\n        return String::new();\n    }\n\n    let mut parser = vt100::Parser::new_with_callbacks(rows, cols, 0, Capture::default());\n    onlcr(input).for_each(|chunk| parser.process(chunk));\n\n    let (screen, capture) = parser.screen_and_callbacks_mut();\n    screen\n        .write_contents_formatted_basic(\n            &mut capture.buffer,\n            vt100::capture::BasicFormattedCaptureRange::Full(&mut capture.state),\n        )","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin-common/src/ansi.rs#L41-L77","documentation":"`on_scroll` writes vt100 row contents into a `String` buffer via `write_formatted_basic` and unwraps the `Result` with `.expect(\"writing to a String cannot fail\")`. The error type from rmp/vt100-style writers cannot occur when the target is a `String` (no capacity or IO errors), so this is an infallibility assertion, not a real runtime failure.","triggerScenarios":"Only via a library bug: the underlying `write_formatted_basic` implementation returning `Err` despite writing to a `String` (e.g. a breaking change in the vt100 crate's API contract).","commonSituations":"Effectively never; appears in terminal scrollback rendering inside the TUI when new screen contents are captured.","solutions":["Pin/upgrade the `vt100` crate and confirm `write_formatted_basic` still returns an infallible-for-String error type","If it can now fail, propagate the error instead of expecting"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// infallible in practice; if the vt100 API becomes fallible:\nif let Err(e) = contents.write_formatted_basic(&mut self.buffer, &mut self.state) {\n    log::warn!(\"failed to format scroll contents: {e}\");\n    return;\n}","preventionTips":["Pin the vt100 crate version and review its changelog on upgrade","Add a comment/doc test asserting String writes remain infallible"],"tags":["panic","infallible","terminal","vt100"],"backgroundTag":"internal-invariant-violation","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}