{"record":{"id":"45649493e0de678c","repo":"tursodatabase/turso","slug":"invaliddata","errorCode":"InvalidData","errorMessage":"non-UTF8 SQL: {e}","messagePattern":"non-UTF8 SQL: (.+?)","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"cli/input.rs","lineNumber":288,"sourceCode":"        // Skip if buffer empty or no ';'\n        if let Some(semicolon_pos) = self.buf.iter().rposition(|&b| b == b';') {\n            // Are all bytes after ';' ASCII whitespace?\n            if self.buf[semicolon_pos + 1..]\n                .iter()\n                .all(|&b| matches!(b, b' ' | b'\\t' | b'\\r' | b'\\n'))\n            {\n                let stmt_bytes = self.buf[..=semicolon_pos].to_vec();\n                self.buf.clear();\n                self.exec_stmt_bytes(&stmt_bytes)?;\n            }\n        }\n        Ok(())\n    }\n\n    fn exec_stmt_bytes(&self, stmt_bytes: &[u8]) -> io::Result<()> {\n        // SQL must be UTF-8. If not, surface a clear error.\n        let sql = std::str::from_utf8(stmt_bytes).map_err(|e| {\n            io::Error::new(io::ErrorKind::InvalidData, format!(\"non-UTF8 SQL: {e}\"))\n        })?;\n        self.exec_stmt(sql)\n            .map_err(|e| io::Error::other(e.to_string()))\n    }\n\n    fn exec_stmt(&self, sql: &str) -> Result<(), LimboError> {\n        match self.target.query(sql) {\n            Ok(Some(mut rows)) => {\n                rows.run_with_row_callback(|_| Ok(()))?;\n            }\n            Ok(None) => {}\n            Err(e) => return Err(e),\n        }\n        Ok(())\n    }\n}\n\nimpl<'a> Write for ApplyWriter<'a> {","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/input.rs#L270-L306","documentation":"The tursodb CLI buffers stdin until a ';' and must convert the statement bytes to a Rust string; if they are not valid UTF-8 it fails fast with io::ErrorKind::InvalidData instead of executing mojibake SQL.","triggerScenarios":"Piping SQL that is not UTF-8: latin-1/CP1252 dumps, UTF-16 files (e.g. PowerShell redirects), BOM-prefixed UTF-16, or binary/gzip files fed without decompression.","commonSituations":"`cat dump.sql | tursodb` where dump.sql came from Windows tooling, exports in legacy encodings, or accidentally piping a .gz archive.","solutions":["Convert the input to UTF-8: `iconv -f UTF-16 -t UTF-8 dump.sql | tursodb`","Decompress first: `gunzip -c dump.sql.gz | tursodb`","Strip a BOM with `sed '1s/^\\xEF\\xBB\\xBF//'` or an editor","Verify with `file dump.sql` before piping"],"exampleFix":"# before (PowerShell emits UTF-16)\nGet-Content dump.sql | tursodb\n# after\niconv -f UTF-16 -t UTF-8 dump.sql | tursodb","handlingStrategy":"validation","validationCode":"# verify encoding before piping\nfile dump.sql\niconv -f UTF-8 -t UTF-8 dump.sql >/dev/null && echo utf8-ok","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always export SQL dumps as UTF-8","Check `file` output before `cat | tursodb`","Never pipe compressed files directly - decompress first"],"tags":["cli","encoding","utf-8","stdin","input-validation"],"backgroundTag":"invalid-utf8","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}