diff --git a/src/core/protocol/commands/check_authorization.rs b/src/core/protocol/commands/check_authorization.rs index 61aacd5..d68ddfb 100644 --- a/src/core/protocol/commands/check_authorization.rs +++ b/src/core/protocol/commands/check_authorization.rs @@ -48,6 +48,7 @@ pub fn print_check_authorization_output_status_json(output: &CheckAuthorizationR db_or_user.name().to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(db_or_user), }), ), @@ -77,4 +78,12 @@ impl CheckAuthorizationError { // } } } + + pub fn error_type(&self) -> &'static str { + match self { + CheckAuthorizationError::SanitizationError(_) => "sanitization-error", + CheckAuthorizationError::OwnershipError(_) => "ownership-error", + // CheckAuthorizationError::AuthorizationHandlerError(_) => "authorization-handler-error", + } + } } diff --git a/src/core/protocol/commands/create_databases.rs b/src/core/protocol/commands/create_databases.rs index 1ba2125..8f25a53 100644 --- a/src/core/protocol/commands/create_databases.rs +++ b/src/core/protocol/commands/create_databases.rs @@ -44,6 +44,7 @@ pub fn print_create_databases_output_status_json(output: &CreateDatabasesRespons name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -73,4 +74,13 @@ impl CreateDatabaseError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + CreateDatabaseError::SanitizationError(_) => "sanitization-error", + CreateDatabaseError::OwnershipError(_) => "ownership-error", + CreateDatabaseError::DatabaseAlreadyExists => "database-already-exists", + CreateDatabaseError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/create_users.rs b/src/core/protocol/commands/create_users.rs index 9ca3535..fb6efb1 100644 --- a/src/core/protocol/commands/create_users.rs +++ b/src/core/protocol/commands/create_users.rs @@ -44,6 +44,7 @@ pub fn print_create_users_output_status_json(output: &CreateUsersResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -73,4 +74,13 @@ impl CreateUserError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + CreateUserError::SanitizationError(_) => "sanitization-error", + CreateUserError::OwnershipError(_) => "ownership-error", + CreateUserError::UserAlreadyExists => "user-already-exists", + CreateUserError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/drop_databases.rs b/src/core/protocol/commands/drop_databases.rs index 063c0e8..40e323c 100644 --- a/src/core/protocol/commands/drop_databases.rs +++ b/src/core/protocol/commands/drop_databases.rs @@ -47,6 +47,7 @@ pub fn print_drop_databases_output_status_json(output: &DropDatabasesResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -76,4 +77,13 @@ impl DropDatabaseError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + DropDatabaseError::SanitizationError(_) => "sanitization-error", + DropDatabaseError::OwnershipError(_) => "ownership-error", + DropDatabaseError::DatabaseDoesNotExist => "database-does-not-exist", + DropDatabaseError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/drop_users.rs b/src/core/protocol/commands/drop_users.rs index 609690d..ce7cc69 100644 --- a/src/core/protocol/commands/drop_users.rs +++ b/src/core/protocol/commands/drop_users.rs @@ -44,6 +44,7 @@ pub fn print_drop_users_output_status_json(output: &DropUsersResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -73,4 +74,13 @@ impl DropUserError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + DropUserError::SanitizationError(_) => "sanitization-error", + DropUserError::OwnershipError(_) => "ownership-error", + DropUserError::UserDoesNotExist => "user-does-not-exist", + DropUserError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/list_databases.rs b/src/core/protocol/commands/list_databases.rs index 9b9badc..3232928 100644 --- a/src/core/protocol/commands/list_databases.rs +++ b/src/core/protocol/commands/list_databases.rs @@ -63,6 +63,7 @@ pub fn print_list_databases_output_status_json(output: &ListDatabasesResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -92,4 +93,13 @@ impl ListDatabasesError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + ListDatabasesError::SanitizationError(_) => "sanitization-error", + ListDatabasesError::OwnershipError(_) => "ownership-error", + ListDatabasesError::DatabaseDoesNotExist => "database-does-not-exist", + ListDatabasesError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/list_privileges.rs b/src/core/protocol/commands/list_privileges.rs index 25e8bb7..24dd37e 100644 --- a/src/core/protocol/commands/list_privileges.rs +++ b/src/core/protocol/commands/list_privileges.rs @@ -89,6 +89,7 @@ pub fn print_list_privileges_output_status_json(output: &ListPrivilegesResponse) name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -126,4 +127,13 @@ impl GetDatabasesPrivilegeDataError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + GetDatabasesPrivilegeDataError::SanitizationError(_) => "sanitization-error", + GetDatabasesPrivilegeDataError::OwnershipError(_) => "ownership-error", + GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => "database-does-not-exist", + GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/list_users.rs b/src/core/protocol/commands/list_users.rs index cea9a84..2c2f1ee 100644 --- a/src/core/protocol/commands/list_users.rs +++ b/src/core/protocol/commands/list_users.rs @@ -78,6 +78,7 @@ pub fn print_list_users_output_status_json(output: &ListUsersResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -107,4 +108,13 @@ impl ListUsersError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + ListUsersError::SanitizationError(_) => "sanitization-error", + ListUsersError::OwnershipError(_) => "ownership-error", + ListUsersError::UserDoesNotExist => "user-does-not-exist", + ListUsersError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/lock_users.rs b/src/core/protocol/commands/lock_users.rs index 1b25f85..28af361 100644 --- a/src/core/protocol/commands/lock_users.rs +++ b/src/core/protocol/commands/lock_users.rs @@ -45,6 +45,7 @@ pub fn print_lock_users_output_status_json(output: &LockUsersResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -77,4 +78,14 @@ impl LockUserError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + LockUserError::SanitizationError(_) => "sanitization-error", + LockUserError::OwnershipError(_) => "ownership-error", + LockUserError::UserDoesNotExist => "user-does-not-exist", + LockUserError::UserIsAlreadyLocked => "user-is-already-locked", + LockUserError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/modify_privileges.rs b/src/core/protocol/commands/modify_privileges.rs index 58d894a..80bf3f5 100644 --- a/src/core/protocol/commands/modify_privileges.rs +++ b/src/core/protocol/commands/modify_privileges.rs @@ -79,6 +79,31 @@ impl ModifyDatabasePrivilegesError { } } } + + #[allow(dead_code)] + pub fn error_type(&self) -> &'static str { + match self { + ModifyDatabasePrivilegesError::DatabaseSanitizationError(_) => { + "database-sanitization-error" + } + ModifyDatabasePrivilegesError::DatabaseOwnershipError(_) => "database-ownership-error", + ModifyDatabasePrivilegesError::UserSanitizationError(_) => "user-sanitization-error", + ModifyDatabasePrivilegesError::UserOwnershipError(_) => "user-ownership-error", + ModifyDatabasePrivilegesError::DatabaseDoesNotExist => "database-does-not-exist", + ModifyDatabasePrivilegesError::DiffDoesNotApply(err) => match err { + DiffDoesNotApplyError::RowAlreadyExists(_, _) => { + "diff-does-not-apply/row-already-exists" + } + DiffDoesNotApplyError::RowDoesNotExist(_, _) => { + "diff-does-not-apply/row-does-not-exist" + } + DiffDoesNotApplyError::RowPrivilegeChangeDoesNotApply(_, _) => { + "diff-does-not-apply/row-privilege-change-does-not-apply" + } + }, + ModifyDatabasePrivilegesError::MySqlError(_) => "mysql-error", + } + } } impl DiffDoesNotApplyError { diff --git a/src/core/protocol/commands/passwd_user.rs b/src/core/protocol/commands/passwd_user.rs index 8ee97e1..1af1d1f 100644 --- a/src/core/protocol/commands/passwd_user.rs +++ b/src/core/protocol/commands/passwd_user.rs @@ -46,4 +46,14 @@ impl SetPasswordError { } } } + + #[allow(dead_code)] + pub fn error_type(&self) -> &'static str { + match self { + SetPasswordError::SanitizationError(_) => "sanitization-error", + SetPasswordError::OwnershipError(_) => "ownership-error", + SetPasswordError::UserDoesNotExist => "user-does-not-exist", + SetPasswordError::MySqlError(_) => "mysql-error", + } + } } diff --git a/src/core/protocol/commands/unlock_users.rs b/src/core/protocol/commands/unlock_users.rs index bbad4e4..ac2fe63 100644 --- a/src/core/protocol/commands/unlock_users.rs +++ b/src/core/protocol/commands/unlock_users.rs @@ -45,6 +45,7 @@ pub fn print_unlock_users_output_status_json(output: &UnlockUsersResponse) { name.to_string(), json!({ "status": "error", + "type": err.error_type(), "error": err.to_error_message(name), }), ), @@ -77,4 +78,14 @@ impl UnlockUserError { } } } + + pub fn error_type(&self) -> &'static str { + match self { + UnlockUserError::SanitizationError(_) => "sanitization-error", + UnlockUserError::OwnershipError(_) => "ownership-error", + UnlockUserError::UserDoesNotExist => "user-does-not-exist", + UnlockUserError::UserIsAlreadyUnlocked => "user-is-already-unlocked", + UnlockUserError::MySqlError(_) => "mysql-error", + } + } }