diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-03-05 08:30:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-05 08:30:41 -0500 |
commit | 54a1688868810af0ef16f5c186dfb839f2fce23f (patch) | |
tree | 4aa8a2a1f1b9856c3d242e4a891645fda361767a /cli/op_error.rs | |
parent | 444b1ab68efdf0ceb36dc4a495ac83c809e15b2b (diff) |
Allow BadResource errors to take a custom message (#4251)
Diffstat (limited to 'cli/op_error.rs')
-rw-r--r-- | cli/op_error.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/cli/op_error.rs b/cli/op_error.rs index d81d4cad1..d35c99895 100644 --- a/cli/op_error.rs +++ b/cli/op_error.rs @@ -91,8 +91,13 @@ impl OpError { Self::new(ErrorKind::PermissionDenied, msg) } - pub fn bad_resource() -> OpError { - Self::new(ErrorKind::BadResource, "bad resource id".to_string()) + pub fn bad_resource(msg: String) -> OpError { + Self::new(ErrorKind::BadResource, msg) + } + + // BadResource usually needs no additional detail, hence this helper. + pub fn bad_resource_id() -> OpError { + Self::new(ErrorKind::BadResource, "Bad resource ID".to_string()) } } @@ -444,10 +449,18 @@ mod tests { #[test] fn test_bad_resource() { - let err = OpError::bad_resource(); + let err = OpError::bad_resource("Resource has been closed".to_string()); assert_eq!(err.kind, ErrorKind::BadResource); - assert_eq!(err.to_string(), "bad resource id"); + assert_eq!(err.to_string(), "Resource has been closed"); } + + #[test] + fn test_bad_resource_id() { + let err = OpError::bad_resource_id(); + assert_eq!(err.kind, ErrorKind::BadResource); + assert_eq!(err.to_string(), "Bad resource ID"); + } + #[test] fn test_permission_denied() { let err = OpError::permission_denied( |