client: add error subtypes for name and owner validation in json output

This commit is contained in:
2025-12-04 12:18:50 +09:00
parent f5d3c46e60
commit 1e7911023e
16 changed files with 156 additions and 75 deletions

View File

@@ -79,11 +79,14 @@ impl CheckAuthorizationError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
CheckAuthorizationError::SanitizationError(_) => "sanitization-error",
CheckAuthorizationError::OwnershipError(_) => "ownership-error",
// CheckAuthorizationError::AuthorizationHandlerError(_) => "authorization-handler-error",
CheckAuthorizationError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
CheckAuthorizationError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
} // CheckAuthorizationError::AuthorizationHandlerError(_) => "authorization-handler-error".to_string(),
}
}
}

View File

@@ -75,12 +75,16 @@ impl CreateDatabaseError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
CreateDatabaseError::SanitizationError(_) => "sanitization-error",
CreateDatabaseError::OwnershipError(_) => "ownership-error",
CreateDatabaseError::DatabaseAlreadyExists => "database-already-exists",
CreateDatabaseError::MySqlError(_) => "mysql-error",
CreateDatabaseError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
CreateDatabaseError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
}
CreateDatabaseError::DatabaseAlreadyExists => "database-already-exists".to_string(),
CreateDatabaseError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -75,12 +75,14 @@ impl CreateUserError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
CreateUserError::SanitizationError(_) => "sanitization-error",
CreateUserError::OwnershipError(_) => "ownership-error",
CreateUserError::UserAlreadyExists => "user-already-exists",
CreateUserError::MySqlError(_) => "mysql-error",
CreateUserError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
CreateUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
CreateUserError::UserAlreadyExists => "user-already-exists".to_string(),
CreateUserError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -78,12 +78,16 @@ impl DropDatabaseError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
DropDatabaseError::SanitizationError(_) => "sanitization-error",
DropDatabaseError::OwnershipError(_) => "ownership-error",
DropDatabaseError::DatabaseDoesNotExist => "database-does-not-exist",
DropDatabaseError::MySqlError(_) => "mysql-error",
DropDatabaseError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
DropDatabaseError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
}
DropDatabaseError::DatabaseDoesNotExist => "database-does-not-exist".to_string(),
DropDatabaseError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -75,12 +75,14 @@ impl DropUserError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
DropUserError::SanitizationError(_) => "sanitization-error",
DropUserError::OwnershipError(_) => "ownership-error",
DropUserError::UserDoesNotExist => "user-does-not-exist",
DropUserError::MySqlError(_) => "mysql-error",
DropUserError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
DropUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
DropUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
DropUserError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -15,4 +15,11 @@ impl ListAllDatabasesError {
ListAllDatabasesError::MySqlError(err) => format!("MySQL error: {}", err),
}
}
#[allow(dead_code)]
pub fn error_type(&self) -> String {
match self {
ListAllDatabasesError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -16,4 +16,11 @@ impl GetAllDatabasesPrivilegeDataError {
GetAllDatabasesPrivilegeDataError::MySqlError(err) => format!("MySQL error: {}", err),
}
}
#[allow(dead_code)]
pub fn error_type(&self) -> String {
match self {
GetAllDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -15,4 +15,11 @@ impl ListAllUsersError {
ListAllUsersError::MySqlError(err) => format!("MySQL error: {}", err),
}
}
#[allow(dead_code)]
pub fn error_type(&self) -> String {
match self {
ListAllUsersError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -94,12 +94,16 @@ impl ListDatabasesError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
ListDatabasesError::SanitizationError(_) => "sanitization-error",
ListDatabasesError::OwnershipError(_) => "ownership-error",
ListDatabasesError::DatabaseDoesNotExist => "database-does-not-exist",
ListDatabasesError::MySqlError(_) => "mysql-error",
ListDatabasesError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
ListDatabasesError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
}
ListDatabasesError::DatabaseDoesNotExist => "database-does-not-exist".to_string(),
ListDatabasesError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -128,12 +128,18 @@ impl GetDatabasesPrivilegeDataError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
GetDatabasesPrivilegeDataError::SanitizationError(_) => "sanitization-error",
GetDatabasesPrivilegeDataError::OwnershipError(_) => "ownership-error",
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => "database-does-not-exist",
GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error",
GetDatabasesPrivilegeDataError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
GetDatabasesPrivilegeDataError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
}
GetDatabasesPrivilegeDataError::DatabaseDoesNotExist => {
"database-does-not-exist".to_string()
}
GetDatabasesPrivilegeDataError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -109,12 +109,14 @@ impl ListUsersError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
ListUsersError::SanitizationError(_) => "sanitization-error",
ListUsersError::OwnershipError(_) => "ownership-error",
ListUsersError::UserDoesNotExist => "user-does-not-exist",
ListUsersError::MySqlError(_) => "mysql-error",
ListUsersError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
ListUsersError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
ListUsersError::UserDoesNotExist => "user-does-not-exist".to_string(),
ListUsersError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -79,13 +79,15 @@ impl LockUserError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
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",
LockUserError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
LockUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
LockUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
LockUserError::UserIsAlreadyLocked => "user-is-already-locked".to_string(),
LockUserError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -81,27 +81,27 @@ impl ModifyDatabasePrivilegesError {
}
#[allow(dead_code)]
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
ModifyDatabasePrivilegesError::DatabaseSanitizationError(_) => {
"database-sanitization-error"
ModifyDatabasePrivilegesError::DatabaseSanitizationError(err) => {
format!("database-sanitization-error/{}", err.error_type())
}
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"
ModifyDatabasePrivilegesError::DatabaseOwnershipError(err) => {
format!("database-ownership-error/{}", err.error_type())
}
DiffDoesNotApplyError::RowDoesNotExist(_, _) => {
"diff-does-not-apply/row-does-not-exist"
ModifyDatabasePrivilegesError::UserSanitizationError(err) => {
format!("user-sanitization-error/{}", err.error_type())
}
DiffDoesNotApplyError::RowPrivilegeChangeDoesNotApply(_, _) => {
"diff-does-not-apply/row-privilege-change-does-not-apply"
ModifyDatabasePrivilegesError::UserOwnershipError(err) => {
format!("user-ownership-error/{}", err.error_type())
}
},
ModifyDatabasePrivilegesError::MySqlError(_) => "mysql-error",
ModifyDatabasePrivilegesError::DatabaseDoesNotExist => {
"database-does-not-exist".to_string()
}
ModifyDatabasePrivilegesError::DiffDoesNotApply(err) => {
format!("diff-does-not-apply/{}", err.error_type())
}
ModifyDatabasePrivilegesError::MySqlError(_) => "mysql-error".to_string(),
}
}
}
@@ -129,4 +129,14 @@ impl DiffDoesNotApplyError {
}
}
}
pub fn error_type(&self) -> String {
match self {
DiffDoesNotApplyError::RowAlreadyExists(_, _) => "row-already-exists".to_string(),
DiffDoesNotApplyError::RowDoesNotExist(_, _) => "row-does-not-exist".to_string(),
DiffDoesNotApplyError::RowPrivilegeChangeDoesNotApply(_, _) => {
"row-privilege-change-does-not-apply".to_string()
}
}
}
}

View File

@@ -48,12 +48,16 @@ impl SetPasswordError {
}
#[allow(dead_code)]
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
match self {
SetPasswordError::SanitizationError(_) => "sanitization-error",
SetPasswordError::OwnershipError(_) => "ownership-error",
SetPasswordError::UserDoesNotExist => "user-does-not-exist",
SetPasswordError::MySqlError(_) => "mysql-error",
SetPasswordError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
SetPasswordError::OwnershipError(err) => {
format!("ownership-error/{}", err.error_type())
}
SetPasswordError::UserDoesNotExist => "user-does-not-exist".to_string(),
SetPasswordError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -79,13 +79,15 @@ impl UnlockUserError {
}
}
pub fn error_type(&self) -> &'static str {
pub fn error_type(&self) -> String {
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",
UnlockUserError::SanitizationError(err) => {
format!("sanitization-error/{}", err.error_type())
}
UnlockUserError::OwnershipError(err) => format!("ownership-error/{}", err.error_type()),
UnlockUserError::UserDoesNotExist => "user-does-not-exist".to_string(),
UnlockUserError::UserIsAlreadyUnlocked => "user-is-already-unlocked".to_string(),
UnlockUserError::MySqlError(_) => "mysql-error".to_string(),
}
}
}

View File

@@ -34,6 +34,14 @@ impl NameValidationError {
.to_owned(),
}
}
pub fn error_type(&self) -> &'static str {
match self {
NameValidationError::EmptyString => "empty-string",
NameValidationError::InvalidCharacters => "invalid-characters",
NameValidationError::TooLong => "too-long",
}
}
}
impl OwnerValidationError {
@@ -81,6 +89,13 @@ impl OwnerValidationError {
.to_string(),
}
}
pub fn error_type(&self) -> &'static str {
match self {
OwnerValidationError::NoMatch => "no-match",
OwnerValidationError::StringEmpty => "string-empty",
}
}
}
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]