diff --git a/changelog.d/20261008-database-error-not-misread.md b/changelog.d/20261008-database-error-not-misread.md new file mode 100644 index 0000000..e98b252 --- /dev/null +++ b/changelog.d/20261008-database-error-not-misread.md @@ -0,0 +1,7 @@ +--- +area: manager +type: fixed +audience: admins +title: A failing database update is no longer reported as "database not running" +--- +An SQL error whose message contained the number 2003, such as an out-of-range value, was shown as "The database is not running". The real error is now shown. diff --git a/crates/coa-core/src/db.rs b/crates/coa-core/src/db.rs index 0024b7a..0786ad6 100644 --- a/crates/coa-core/src/db.rs +++ b/crates/coa-core/src/db.rs @@ -176,10 +176,13 @@ impl Db { fn fail(&self, stderr: &[u8]) -> Error { let text = String::from_utf8_lossy(stderr); - let down = text.contains("2003") || text.contains("Can't connect") || text.contains("is not running") || text.contains("No such container"); + // Only the client's own connection errors mean "not running": the number 2003 or the words can also appear inside + // the message of an ordinary SQL error (a duplicate entry, a row number) and must not hide it. + let down = text.contains("ERROR 2003") || text.contains("ERROR 2002") || text.contains("Can't connect to MySQL server") + || text.contains("No such container") || text.contains("is not running"); let code = if down { ErrorCode::DatabaseNotRunning } else { ErrorCode::Unknown }; match code { - ErrorCode::DatabaseNotRunning => Error::Invalid("The database is not running. Start the server first.".into()), + ErrorCode::DatabaseNotRunning => Error::Invalid(format!("The database is not running. Start the server first. ({})", text.trim().lines().last().unwrap_or("").chars().take(300).collect::())), _ => Error::Invalid(format!("database command failed: {}", text.trim().lines().last().unwrap_or(""))), } }