xref: /DragonOS/user/apps/user-manage/src/error/error.rs (revision 79ad6e5ba4cf7fd624dfa91a1de35d7e60bdda43)
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` - 退出状态码
29     pub fn error_handle(error: String, exit_status: ExitStatus) {
30         eprintln!("{error}");
31         exit(exit_status as i32);
32     }
33 }
34