This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherror.rs
60 lines (48 loc) · 1.65 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::num;
use failure::Fail;
use http;
use nserror::{nsresult, NS_ERROR_INVALID_ARG, NS_ERROR_NOT_AVAILABLE};
#[derive(Debug, Fail)]
pub enum RemoteAgentError {
#[fail(display = "expected address syntax [<host>]:<port>: {}", _0)]
AddressSpec(http::uri::InvalidUri),
#[fail(display = "conflicting flags --remote-debugger and --remote-debugging-port")]
FlagConflict,
#[fail(display = "invalid port: {}", _0)]
InvalidPort(num::ParseIntError),
#[fail(display = "missing port number")]
MissingPort,
#[fail(display = "unavailable")]
Unavailable,
#[fail(display = "error result {}", _0)]
XpCom(nsresult),
}
impl From<RemoteAgentError> for nsresult {
fn from(err: RemoteAgentError) -> nsresult {
use RemoteAgentError::*;
match err {
AddressSpec(_) | InvalidPort(_) => NS_ERROR_INVALID_ARG,
MissingPort | FlagConflict => NS_ERROR_INVALID_ARG,
Unavailable => NS_ERROR_NOT_AVAILABLE,
XpCom(result) => result,
}
}
}
impl From<num::ParseIntError> for RemoteAgentError {
fn from(err: num::ParseIntError) -> Self {
RemoteAgentError::InvalidPort(err)
}
}
impl From<http::uri::InvalidUri> for RemoteAgentError {
fn from(err: http::uri::InvalidUri) -> Self {
RemoteAgentError::AddressSpec(err)
}
}
impl From<nsresult> for RemoteAgentError {
fn from(result: nsresult) -> Self {
RemoteAgentError::XpCom(result)
}
}