diff rust/rhg/src/error.rs @ 45924:a2eda1ff22aa

requirements: move loading to hg-core and add parsing No functional change, checking comes later. Differential Revision: https://phab.mercurial-scm.org/D9398
author Simon Sapin <simon-commits@exyr.org>
date Tue, 24 Nov 2020 17:49:16 +0100
parents ead435aa5294
children 2ad2745e0be9
line wrap: on
line diff
--- a/rust/rhg/src/error.rs	Tue Nov 24 15:11:58 2020 +0100
+++ b/rust/rhg/src/error.rs	Tue Nov 24 17:49:16 2020 +0100
@@ -1,6 +1,7 @@
 use crate::exitcode;
 use crate::ui::UiError;
 use hg::operations::{FindRootError, FindRootErrorKind};
+use hg::requirements::RequirementsError;
 use hg::utils::files::get_bytes_from_path;
 use std::convert::From;
 use std::path::PathBuf;
@@ -12,9 +13,8 @@
     RootNotFound(PathBuf),
     /// The current directory cannot be found
     CurrentDirNotFound(std::io::Error),
-    /// Error while reading or writing a file
-    // TODO: add the file name/path?
-    FileError(std::io::Error),
+    /// `.hg/requires`
+    RequirementsError(RequirementsError),
     /// The standard output stream cannot be written to
     StdoutError,
     /// The standard error stream cannot be written to
@@ -30,7 +30,7 @@
         match self {
             CommandErrorKind::RootNotFound(_) => exitcode::ABORT,
             CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
-            CommandErrorKind::FileError(_) => exitcode::ABORT,
+            CommandErrorKind::RequirementsError(_) => exitcode::ABORT,
             CommandErrorKind::StdoutError => exitcode::ABORT,
             CommandErrorKind::StderrError => exitcode::ABORT,
             CommandErrorKind::Abort(_) => exitcode::ABORT,
@@ -62,6 +62,11 @@
                 ]
                 .concat(),
             ),
+            CommandErrorKind::RequirementsError(
+                RequirementsError::Corrupted,
+            ) => Some(
+                "abort: .hg/requires is corrupted\n".as_bytes().to_owned(),
+            ),
             CommandErrorKind::Abort(message) => message.to_owned(),
             _ => None,
         }
@@ -115,3 +120,11 @@
         }
     }
 }
+
+impl From<RequirementsError> for CommandError {
+    fn from(err: RequirementsError) -> Self {
+        CommandError {
+            kind: CommandErrorKind::RequirementsError(err),
+        }
+    }
+}