client: add error type field for --json outputs
Some checks failed
Some checks failed
This commit is contained in:
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user