summaryrefslogtreecommitdiff
path: root/sound_card_init/utils/src/error.rs
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-02-19 23:19:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-02-19 23:19:26 +0000
commita363450d3e76a52535eedc48f75f78aab8801637 (patch)
treed5ef5f1d516d12301b0a65b5dbfea16938588270 /sound_card_init/utils/src/error.rs
parent34d0c37f6956d4bfe8e09f5bc246b03e0d66e618 (diff)
parentdc2b74a983c1182f9f4e05a8e6e91beb04792c51 (diff)
downloadadhd-a363450d3e76a52535eedc48f75f78aab8801637.tar.gz
Merge "Merge branch 'upstream-master'"
Diffstat (limited to 'sound_card_init/utils/src/error.rs')
-rw-r--r--sound_card_init/utils/src/error.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/sound_card_init/utils/src/error.rs b/sound_card_init/utils/src/error.rs
new file mode 100644
index 00000000..93d53b9b
--- /dev/null
+++ b/sound_card_init/utils/src/error.rs
@@ -0,0 +1,39 @@
+// Copyright 2020 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+//! This mod contains all possible errors that can occur within utils.
+use std::fmt;
+use std::io;
+use std::time;
+use std::{error, path::PathBuf};
+
+use remain::sorted;
+
+/// Alias for a `Result` with the error type `utils::Error`.
+pub type Result<T> = std::result::Result<T, Error>;
+
+/// This type represents all possible errors that can occur within utils.
+#[sorted]
+#[derive(Debug)]
+pub enum Error {
+ /// It wraps file path with the io::Error.
+ FileIOFailed(PathBuf, io::Error),
+ /// It wraps file path with the serde_yaml::Error.
+ SerdeError(PathBuf, serde_yaml::Error),
+ /// It wraps time::SystemTimeError.
+ SystemTimeError(time::SystemTimeError),
+}
+
+impl error::Error for Error {}
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use Error::*;
+ match self {
+ FileIOFailed(file, e) => write!(f, "{:?}: {}", file, e),
+ SerdeError(file, e) => write!(f, "{:?}: {}", file, e),
+ SystemTimeError(e) => write!(f, "{}", e),
+ }
+ }
+}