|
| 1 | +use std::fmt::Display; |
| 2 | + |
| 3 | +pub type Result_type<T> = Result<T, Error_type>; |
| 4 | + |
| 5 | +#[derive(Debug, Clone)] |
| 6 | +pub enum Error_type { |
| 7 | + Failed_to_get_current_task_identifier(Task::Error_type), |
| 8 | + Failed_to_read_users_directory(File_system::Error_type), |
| 9 | + Failed_to_get_user_file_path, |
| 10 | + Failed_to_open_user_file(File_system::Error_type), |
| 11 | + Failed_to_read_user_file(File_system::Error_type), |
| 12 | + Failed_to_parse_user_file(miniserde::Error), |
| 13 | + Failed_to_add_user(Users::Error_type), |
| 14 | + Failed_to_get_new_user_identifier(Users::Error_type), |
| 15 | + Failed_to_create_user(Users::Error_type), |
| 16 | + Failed_to_write_user_file(File_system::Error_type), |
| 17 | + Failed_to_read_group_directory(File_system::Error_type), |
| 18 | + Failed_to_get_group_file_path, |
| 19 | + Failed_to_open_group_file(File_system::Error_type), |
| 20 | + Failed_to_read_group_file(File_system::Error_type), |
| 21 | + Failed_to_parse_group_file(miniserde::Error), |
| 22 | + Failed_to_add_group(Users::Error_type), |
| 23 | + Failed_to_get_new_group_identifier(Users::Error_type), |
| 24 | + Failed_to_create_group(Users::Error_type), |
| 25 | + Failed_to_write_group_file(File_system::Error_type), |
| 26 | + Invalid_password, |
| 27 | + Failed_to_open_random_device(File_system::Error_type), |
| 28 | + Failed_to_read_random_device(File_system::Error_type), |
| 29 | + Failed_to_get_user_identifier(Users::Error_type), |
| 30 | +} |
| 31 | + |
| 32 | +impl Display for Error_type { |
| 33 | + fn fmt(&self, Formatter: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 34 | + match self { |
| 35 | + Self::Failed_to_get_current_task_identifier(Error) => { |
| 36 | + write!( |
| 37 | + Formatter, |
| 38 | + "Failed to get current task identifier: {}", |
| 39 | + Error |
| 40 | + ) |
| 41 | + } |
| 42 | + Self::Failed_to_read_users_directory(Error) => { |
| 43 | + write!(Formatter, "Failed to read users directory: {}", Error) |
| 44 | + } |
| 45 | + Self::Failed_to_get_user_file_path => { |
| 46 | + write!(Formatter, "Failed to get user file path") |
| 47 | + } |
| 48 | + Self::Failed_to_read_user_file(Error) => { |
| 49 | + write!(Formatter, "Failed to read user file: {}", Error) |
| 50 | + } |
| 51 | + Self::Failed_to_open_user_file(Error) => { |
| 52 | + write!(Formatter, "Failed to open user file: {}", Error) |
| 53 | + } |
| 54 | + Self::Failed_to_parse_user_file(Error) => { |
| 55 | + write!(Formatter, "Failed to parse user file: {}", Error) |
| 56 | + } |
| 57 | + Self::Failed_to_add_user(Error) => { |
| 58 | + write!(Formatter, "Failed to add user: {}", Error) |
| 59 | + } |
| 60 | + Self::Failed_to_read_group_directory(Error) => { |
| 61 | + write!(Formatter, "Failed to read group directory: {}", Error) |
| 62 | + } |
| 63 | + Self::Failed_to_get_group_file_path => { |
| 64 | + write!(Formatter, "Failed to get group file path") |
| 65 | + } |
| 66 | + Self::Failed_to_open_group_file(Error) => { |
| 67 | + write!(Formatter, "Failed to open group file: {}", Error) |
| 68 | + } |
| 69 | + Self::Failed_to_read_group_file(Error) => { |
| 70 | + write!(Formatter, "Failed to read group file: {}", Error) |
| 71 | + } |
| 72 | + Self::Failed_to_parse_group_file(Error) => { |
| 73 | + write!(Formatter, "Failed to parse group file: {}", Error) |
| 74 | + } |
| 75 | + Self::Failed_to_add_group(Error) => { |
| 76 | + write!(Formatter, "Failed to add group: {}", Error) |
| 77 | + } |
| 78 | + Self::Invalid_password => { |
| 79 | + write!(Formatter, "Invalid password") |
| 80 | + } |
| 81 | + Self::Failed_to_open_random_device(Error) => { |
| 82 | + write!(Formatter, "Failed to open random device: {}", Error) |
| 83 | + } |
| 84 | + Self::Failed_to_read_random_device(Error) => { |
| 85 | + write!(Formatter, "Failed to read random device: {}", Error) |
| 86 | + } |
| 87 | + Self::Failed_to_create_user(Error) => { |
| 88 | + write!(Formatter, "Failed to create user: {}", Error) |
| 89 | + } |
| 90 | + Self::Failed_to_get_new_user_identifier(Error) => { |
| 91 | + write!(Formatter, "Failed to get new user identifier: {}", Error) |
| 92 | + } |
| 93 | + Self::Failed_to_write_user_file(Error) => { |
| 94 | + write!(Formatter, "Failed to write user file: {}", Error) |
| 95 | + } |
| 96 | + Self::Failed_to_get_new_group_identifier(Error) => { |
| 97 | + write!(Formatter, "Failed to get new group identifier: {}", Error) |
| 98 | + } |
| 99 | + Self::Failed_to_create_group(Error) => { |
| 100 | + write!(Formatter, "Failed to create group: {}", Error) |
| 101 | + } |
| 102 | + Self::Failed_to_write_group_file(Error) => { |
| 103 | + write!(Formatter, "Failed to write group file: {}", Error) |
| 104 | + } |
| 105 | + Self::Failed_to_get_user_identifier(Error) => { |
| 106 | + write!(Formatter, "Failed to get user identifier: {}", Error) |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +impl From<Task::Error_type> for Error_type { |
| 113 | + fn from(Error: Task::Error_type) -> Self { |
| 114 | + Self::Failed_to_get_current_task_identifier(Error) |
| 115 | + } |
| 116 | +} |
0 commit comments