diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-02-19 23:19:26 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-19 23:19:26 +0000 |
commit | a363450d3e76a52535eedc48f75f78aab8801637 (patch) | |
tree | d5ef5f1d516d12301b0a65b5dbfea16938588270 /sound_card_init/utils/src/error.rs | |
parent | 34d0c37f6956d4bfe8e09f5bc246b03e0d66e618 (diff) | |
parent | dc2b74a983c1182f9f4e05a8e6e91beb04792c51 (diff) | |
download | adhd-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.rs | 39 |
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), + } + } +} |