chiark / gitweb /
command: Further improve error printing
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 20:08:14 +0000 (21:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 May 2021 20:08:23 +0000 (21:08 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/commands.rs

index 825f2e35522c14e5680726fac79f823039c7e5a9..a6036493609b0149fd203faf8fc8f8922642496e 100644 (file)
@@ -1332,7 +1332,7 @@ impl CommandStream<'_> {
         Err(EOF) => break,
         Err(IO(e)) => Err(e).context("read command stream")?,
         Err(Parse(s)) => {
-          let resp = MgmtResponse::Error { error: ME::ParseFailed(s) };
+          let resp = MgmtResponse::Error { error: ME::CommandParseFailed(s) };
           self.chan.write.write(&resp).context("swrite command stream")?;
         }
       }
index e2471ae3fe27b7164baf5172f63833bd67e3ff89..166b5d9ff6cbdee8f9f6d112074d295fb480e9c4 100644 (file)
@@ -208,52 +208,42 @@ pub enum MgmtGameUpdateMode {
 
 #[derive(Debug,Clone,Error,Serialize,Deserialize)]
 pub enum MgmtError {
-  ParseFailed(String),
-  AuthorisationError,
-  SuperuserAuthorisationRequired,
-  SpecifyAccount,
-  MustSpecifyNick,
-  AlreadyExists,
-  NickCollision,
-  GameBeingDestroyed(#[from] GameBeingDestroyed),
-  GameNotFound,
-  GameCorrupted,
-  AccountNotFound(#[from] AccountNotFound),
-  PlayerNotFound(#[from] PlayerNotFound),
-  PieceNotFound,
-  LimitExceeded,
-  ServerFailure(String),
-  ZCoordinateOverflow(#[from] zcoord::Overflow),
-  BadGlob { pat: String, msg: String },
-  BadSpec(#[from] SpecError),
-  TokenDeliveryFailed(#[from] TokenDeliveryError),
-  CoordinateOverflow(#[from] CoordinateOverflow),
-  TomlSyntaxError(String),
-  TomlStructureError(String),
-  RngIsReal,
-  UploadTruncated,
-  UploadCorrupted,
-  TooManyBundles,
-  BadBundle(String),
-  BundleNotFound,
-  BundlesInUse(String),
-}
-impl Display for MgmtError {
-  #[throws(fmt::Error)]
-  fn fmt(&self, f: &mut fmt::Formatter) {
-    use MgmtError::*;
-    match self {
-      ServerFailure(s) => write!(f, "ServerFailure: {}", &s)?,
-      TokenDeliveryFailed(tde) =>
-        write!(f, "access token delivery failed: {}", &tde)?,
-      _ => <Self as Debug>::fmt(self,f)?,
-    }
-  }
+  #[error("failed to parse protocol command: {0}")] CommandParseFailed(String),
+  #[error("not authorised")]                         AuthorisationError,
+  #[error("superuse authorisation requiredr")] SuperuserAuthorisationRequired,
+  #[error("command requires account specified")]     SpecifyAccount,
+  #[error("command requires nick specified")]        MustSpecifyNick,
+  #[error("object or item already exists")]          AlreadyExists,
+  #[error("game already has player with that nick")] NickCollision,
+  #[error("{0}")] GameBeingDestroyed (#[from] GameBeingDestroyed),
+  #[error("game not found")]                         GameNotFound,
+  #[error("xxx GameCorrupted")]                      GameCorrupted,
+  #[error("{0}")] AccountNotFound     (#[from] AccountNotFound),
+  #[error("{0}")] PlayerNotFound      (#[from] PlayerNotFound),
+  #[error("piece not found in game")]                PieceNotFound,
+  #[error("limit exceeded")]                         LimitExceeded,
+  #[error("server failure: {0}")]                    ServerFailure(String),
+  #[error("{0}")] ZCoordinateOverflow (#[from] zcoord::Overflow),
+  #[error("bad glob pattern: {pat:?}: {msg}")]
+                                           BadGlob { pat: String, msg: String },
+  #[error("{0}")] BadSpec             (#[from] SpecError),
+  #[error("access token delivery failed: {0}")]
+                  TokenDeliveryFailed (#[from] TokenDeliveryError),
+  #[error("{0}")] CoordinateOverflow  (#[from] CoordinateOverflow),
+  #[error("TOML syntax error: {0}")]                 TomlSyntaxError(String),
+  #[error("TOML structure error: {0}")]              TomlStructureError(String),
+  #[error("RNG is real, command not supported")]     RngIsReal,
+  #[error("upload truncated")]                       UploadTruncated,
+  #[error("upload corrupted")]                       UploadCorrupted,
+  #[error("too many bundles")]                       TooManyBundles,
+  #[error("bad bundle: {0}")]                        BadBundle(String),
+  #[error("bundle not found")]                       BundleNotFound,
+  #[error("bundle(s) in use, cannot clear ({0})")]   BundlesInUse(String),
 }
 
 impl From<InternalError> for MgmtError {
   fn from(e: InternalError) -> MgmtError {
-    MgmtError::ServerFailure(format!("ServerFailure {}\n", &e))
+    MgmtError::ServerFailure(format!("internal error: {}\n", &e))
   }
 }