error.rs 673 B

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