xref: /DragonOS/user/apps/user-manage/src/error/error.rs (revision 03746da3d9f3ea616cecdb6e581414002075f866)
1 use std::process::exit;
2 
3 #[derive(Debug)]
4 pub enum ExitStatus {
5     Success = 0,
6     PasswdFile = 1,
7     InvalidCmdSyntax = 2,
8     InvalidArg = 3,
9     UidInUse = 4,
10     GroupNotExist = 6,
11     UsernameInUse = 9,
12     GroupFile = 10,
13     CreateHomeFail = 12,
14     PermissionDenied = -1,
15     ShadowFile = -2,
16     GshadowFile = -3,
17     GroupaddFail = -4,
18 }
19 
20 pub struct ErrorHandler;
21 
22 impl ErrorHandler {
23     /// **错误处理函数**
24     ///
25     /// ## 参数
26     ///
27     /// - `error`错误信息
28     /// - `exit_status` - 退出状态码
error_handle(error: String, exit_status: ExitStatus)29     pub fn error_handle(error: String, exit_status: ExitStatus) {
30         eprintln!("{error}");
31         exit(exit_status as i32);
32     }
33 }
34