зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1739307 - [mozbase-rust] Use thiserror crate. r=webdriver-reviewers,jgraham,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D193352
This commit is contained in:
Родитель
b8cd7eaa7f
Коммит
5f24f5b790
|
@ -3677,6 +3677,7 @@ name = "mozprofile"
|
|||
version = "0.9.1"
|
||||
dependencies = [
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3687,6 +3688,7 @@ dependencies = [
|
|||
"log",
|
||||
"mozprofile",
|
||||
"plist",
|
||||
"thiserror",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
|
@ -3708,6 +3710,7 @@ dependencies = [
|
|||
"regex",
|
||||
"rust-ini",
|
||||
"semver",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -13,3 +13,4 @@ repository = "https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/ru
|
|||
|
||||
[dependencies]
|
||||
tempfile = "3"
|
||||
thiserror = "1"
|
||||
|
|
|
@ -7,11 +7,11 @@ use std::borrow::Borrow;
|
|||
use std::borrow::Cow;
|
||||
use std::char;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io::{self, Write};
|
||||
use std::iter::Iterator;
|
||||
|
||||
use std::str;
|
||||
use thiserror::Error;
|
||||
|
||||
impl PrefReaderError {
|
||||
fn new(message: String, position: Position, parent: Option<Box<dyn Error>>) -> PrefReaderError {
|
||||
|
@ -23,26 +23,6 @@ impl PrefReaderError {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PrefReaderError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{} at line {}, column {}",
|
||||
self.message, self.position.line, self.position.column
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for PrefReaderError {
|
||||
fn description(&self) -> &str {
|
||||
&self.message
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
self.parent.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for PrefReaderError {
|
||||
fn from(err: io::Error) -> PrefReaderError {
|
||||
PrefReaderError::new("IOError".into(), Position::new(), Some(err.into()))
|
||||
|
@ -135,10 +115,12 @@ impl<'a> PrefToken<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("{message} at line {}, column {}", .position.line, .position.column)]
|
||||
pub struct PrefReaderError {
|
||||
message: String,
|
||||
position: Position,
|
||||
#[source]
|
||||
parent: Option<Box<dyn Error>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ repository = "https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/ru
|
|||
log = "0.4"
|
||||
mozprofile = { path = "../mozprofile", version = "0.9" }
|
||||
plist = "1.0"
|
||||
thiserror = "1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winreg = "0.10.1"
|
||||
|
|
|
@ -5,17 +5,14 @@
|
|||
use mozprofile::prefreader::PrefReaderError;
|
||||
use mozprofile::profile::Profile;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::From;
|
||||
use std::error::Error;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::firefox_args::Arg;
|
||||
|
||||
|
@ -85,43 +82,12 @@ pub trait RunnerProcess {
|
|||
fn kill(&mut self) -> io::Result<process::ExitStatus>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RunnerError {
|
||||
Io(io::Error),
|
||||
PrefReader(PrefReaderError),
|
||||
}
|
||||
|
||||
impl fmt::Display for RunnerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
RunnerError::Io(ref err) => match err.kind() {
|
||||
ErrorKind::NotFound => "no such file or directory".fmt(f),
|
||||
_ => err.fmt(f),
|
||||
},
|
||||
RunnerError::PrefReader(ref err) => err.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for RunnerError {
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
Some(match *self {
|
||||
RunnerError::Io(ref err) => err as &dyn Error,
|
||||
RunnerError::PrefReader(ref err) => err as &dyn Error,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for RunnerError {
|
||||
fn from(value: io::Error) -> RunnerError {
|
||||
RunnerError::Io(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrefReaderError> for RunnerError {
|
||||
fn from(value: PrefReaderError) -> RunnerError {
|
||||
RunnerError::PrefReader(value)
|
||||
}
|
||||
#[error("IO Error: {0}")]
|
||||
Io(#[from] io::Error),
|
||||
#[error("PrefReader Error: {0}")]
|
||||
PrefReader(#[from] PrefReaderError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -15,3 +15,4 @@ repository = "https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/ru
|
|||
regex = { version = "1", default-features = false, features = ["perf", "std"] }
|
||||
rust-ini = "0.10"
|
||||
semver = "1.0"
|
||||
thiserror = "1"
|
||||
|
|
|
@ -11,11 +11,11 @@ use crate::platform::ini_path;
|
|||
use ini::Ini;
|
||||
use regex::Regex;
|
||||
use std::default::Default;
|
||||
use std::error;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::str::{self, FromStr};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Details about the version of a Firefox build.
|
||||
#[derive(Clone, Default)]
|
||||
|
@ -267,47 +267,25 @@ fn parse_binary_version(version_str: &str) -> VersionResult<Version> {
|
|||
Version::from_str(version_match.as_str())
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Error)]
|
||||
pub enum Error {
|
||||
/// Error parsing a version string
|
||||
#[error("VersionError: {0}")]
|
||||
VersionError(String),
|
||||
/// Error reading application metadata
|
||||
#[error("MetadataError: {0}")]
|
||||
MetadataError(String),
|
||||
/// Error processing a string as a semver comparator
|
||||
#[error("SemVerError: {0}")]
|
||||
SemVerError(String),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
Error::VersionError(ref x) => {
|
||||
"VersionError: ".fmt(f)?;
|
||||
x.fmt(f)
|
||||
}
|
||||
Error::MetadataError(ref x) => {
|
||||
"MetadataError: ".fmt(f)?;
|
||||
x.fmt(f)
|
||||
}
|
||||
Error::SemVerError(ref e) => {
|
||||
"SemVerError: ".fmt(f)?;
|
||||
e.fmt(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<semver::Error> for Error {
|
||||
fn from(err: semver::Error) -> Error {
|
||||
Error::SemVerError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {
|
||||
fn cause(&self) -> Option<&dyn error::Error> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub type VersionResult<T> = Result<T, Error>;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
|
Загрузка…
Ссылка в новой задаче