{"record":{"id":"bb2ce9e70984b414","repo":"databendlabs/databend","slug":"er-unknown-error-bb2ce9","errorCode":"ER_UNKNOWN_ERROR","errorMessage":"ER_UNKNOWN_ERROR: {error}","messagePattern":"ER_UNKNOWN_ERROR: (.+?)","errorType":"error_code","errorClass":"ErrorCode","httpStatus":null,"severity":"error","filePath":"src/query/service/src/servers/mysql/writers/query_result_writer.rs","lineNumber":397,"sourceCode":"\n                let info = query_result\n                    .extra_info\n                    .map(|r| r.progress_info())\n                    .unwrap_or_default();\n                row_writer.finish_with_info(&info).await?;\n\n                Ok(())\n            }\n        }\n    }\n\n    #[async_backtrace::framed]\n    async fn err(&self, error: &ErrorCode, writer: QueryResultWriter<'a, W>) -> Result<()> {\n        self.session.txn_mgr().lock().set_fail();\n        if error.code() != ErrorCode::ABORTED_QUERY && error.code() != ErrorCode::ABORTED_SESSION {\n            error!(\"OnQuery Error: {:?}\", error);\n            writer\n                .error(ErrorKind::ER_UNKNOWN_ERROR, error.to_string().as_bytes())\n                .await?;\n        } else {\n            writer\n                .error(\n                    ErrorKind::ER_ABORTING_CONNECTION,\n                    error.to_string().as_bytes(),\n                )\n                .await?;\n        }\n\n        Ok(())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/servers/mysql/writers/query_result_writer.rs#L379-L415","documentation":"When query execution fails, the query result writer reports the error to the MySQL client as ER_UNKNOWN_ERROR carrying the internal ErrorCode message. Aborted query/session errors are special-cased to ER_ABORTING_CONNECTION; everything else falls into this generic bucket. It also marks the session's txn manager as failed.","triggerScenarios":"Any Err(ErrorCode) returned while writing a query result via QueryResultWriter::write or ok() — execution errors, serialization failures while streaming data, or aborts not classified as ABORTED_QUERY/ABORTED_SESSION.","commonSituations":"Query failures from bad SQL or permissions, output format serialization errors, kill/race issues surfacing as other codes, storage timeouts during result streaming.","solutions":["Parse the detail after 'ER_UNKNOWN_ERROR: ' — it contains the true internal error message and often a code.","Check server logs for 'OnQuery Error' with the same timestamp to find the root cause.","If an abort/kill is involved, re-run the query; check for admin KILL statements or timeouts.","Fix the underlying query/storage issue indicated in the message (syntax, permissions, memory limits)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// client-side: extract the underlying cause from the packet\ntry:\n    cursor.execute(query)\nexcept mysql.connector.Error as e:\n    cause = str(e).split('ER_UNKNOWN_ERROR: ', 1)[-1]\n    if 'aborted' in cause.lower():\n        reconnect_and_retry()\n    else:\n        raise RuntimeError(cause) from e","preventionTips":["Fix the root cause in the wrapped message instead of retrying blindly.","Detect KILL/timeouts and re-run idempotent queries.","Validate SQL, grants, and memory limits before heavy queries.","Watch server logs ('OnQuery Error') for structured diagnostics."],"tags":["mysql","protocol","query-execution","error-handling"],"backgroundTag":"internal-error","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}