2019-11-22 11:03:21 +03:00
|
|
|
// 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 http;
|
2019-12-04 21:26:38 +03:00
|
|
|
use nserror::{
|
|
|
|
nsresult, NS_ERROR_ILLEGAL_VALUE, NS_ERROR_INVALID_ARG, NS_ERROR_LAUNCHED_CHILD_PROCESS,
|
|
|
|
NS_ERROR_NOT_AVAILABLE,
|
|
|
|
};
|
2020-12-11 17:34:23 +03:00
|
|
|
use thiserror::Error;
|
2019-11-22 11:03:21 +03:00
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[derive(Debug, Error)]
|
2019-11-22 11:03:21 +03:00
|
|
|
pub enum RemoteAgentError {
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("expected address syntax [<host>]:<port>: {0}")]
|
|
|
|
AddressSpec(#[from] http::uri::InvalidUri),
|
2019-11-22 11:03:21 +03:00
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("may only be instantiated in parent process")]
|
2019-12-04 21:26:38 +03:00
|
|
|
ChildProcess,
|
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("invalid port: {0}")]
|
|
|
|
InvalidPort(#[from] num::ParseIntError),
|
2019-11-22 11:03:21 +03:00
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("listener restricted to loopback devices")]
|
2019-12-04 21:26:38 +03:00
|
|
|
LoopbackRestricted,
|
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("missing port number")]
|
2019-11-22 11:03:21 +03:00
|
|
|
MissingPort,
|
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("unavailable")]
|
2019-11-22 11:03:21 +03:00
|
|
|
Unavailable,
|
|
|
|
|
2020-12-11 17:34:23 +03:00
|
|
|
#[error("error result {0}")]
|
|
|
|
XpCom(#[source] nsresult),
|
2019-11-22 11:03:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RemoteAgentError> for nsresult {
|
|
|
|
fn from(err: RemoteAgentError) -> nsresult {
|
|
|
|
use RemoteAgentError::*;
|
|
|
|
match err {
|
|
|
|
AddressSpec(_) | InvalidPort(_) => NS_ERROR_INVALID_ARG,
|
2019-12-04 21:26:38 +03:00
|
|
|
ChildProcess => NS_ERROR_LAUNCHED_CHILD_PROCESS,
|
|
|
|
LoopbackRestricted => NS_ERROR_ILLEGAL_VALUE,
|
2020-10-07 16:50:57 +03:00
|
|
|
MissingPort => NS_ERROR_INVALID_ARG,
|
2019-11-22 11:03:21 +03:00
|
|
|
Unavailable => NS_ERROR_NOT_AVAILABLE,
|
|
|
|
XpCom(result) => result,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<nsresult> for RemoteAgentError {
|
|
|
|
fn from(result: nsresult) -> Self {
|
2019-12-04 21:26:38 +03:00
|
|
|
use RemoteAgentError::*;
|
|
|
|
match result {
|
|
|
|
NS_ERROR_NOT_AVAILABLE => Unavailable,
|
|
|
|
NS_ERROR_LAUNCHED_CHILD_PROCESS => ChildProcess,
|
|
|
|
x => RemoteAgentError::XpCom(x),
|
|
|
|
}
|
2019-11-22 11:03:21 +03:00
|
|
|
}
|
|
|
|
}
|