зеркало из https://github.com/mozilla/gecko-dev.git
bug 1590828: remote: take appropriate action on errors during startup r=remote-protocol-reviewers,maja_zf,whimboo
Now that nsIRemoteAgent propagates errors correctly to Rust we can report errors back to the user when something terrible happens. The effect of all this is that the startup handler can stop Firefox when the remote agent fails to listen. Differential Revision: https://phabricator.services.mozilla.com/D55178 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
22560f18d6
Коммит
6eca1da818
|
@ -6,19 +6,28 @@ use std::num;
|
|||
|
||||
use failure::Fail;
|
||||
use http;
|
||||
use nserror::{nsresult, NS_ERROR_INVALID_ARG, NS_ERROR_NOT_AVAILABLE};
|
||||
use nserror::{
|
||||
nsresult, NS_ERROR_ILLEGAL_VALUE, NS_ERROR_INVALID_ARG, NS_ERROR_LAUNCHED_CHILD_PROCESS,
|
||||
NS_ERROR_NOT_AVAILABLE,
|
||||
};
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum RemoteAgentError {
|
||||
#[fail(display = "expected address syntax [<host>]:<port>: {}", _0)]
|
||||
AddressSpec(http::uri::InvalidUri),
|
||||
|
||||
#[fail(display = "may only be instantiated in parent process")]
|
||||
ChildProcess,
|
||||
|
||||
#[fail(display = "conflicting flags --remote-debugger and --remote-debugging-port")]
|
||||
FlagConflict,
|
||||
|
||||
#[fail(display = "invalid port: {}", _0)]
|
||||
InvalidPort(num::ParseIntError),
|
||||
|
||||
#[fail(display = "listener restricted to loopback devices")]
|
||||
LoopbackRestricted,
|
||||
|
||||
#[fail(display = "missing port number")]
|
||||
MissingPort,
|
||||
|
||||
|
@ -34,6 +43,8 @@ impl From<RemoteAgentError> for nsresult {
|
|||
use RemoteAgentError::*;
|
||||
match err {
|
||||
AddressSpec(_) | InvalidPort(_) => NS_ERROR_INVALID_ARG,
|
||||
ChildProcess => NS_ERROR_LAUNCHED_CHILD_PROCESS,
|
||||
LoopbackRestricted => NS_ERROR_ILLEGAL_VALUE,
|
||||
MissingPort | FlagConflict => NS_ERROR_INVALID_ARG,
|
||||
Unavailable => NS_ERROR_NOT_AVAILABLE,
|
||||
XpCom(result) => result,
|
||||
|
@ -55,6 +66,11 @@ impl From<http::uri::InvalidUri> for RemoteAgentError {
|
|||
|
||||
impl From<nsresult> for RemoteAgentError {
|
||||
fn from(result: nsresult) -> Self {
|
||||
RemoteAgentError::XpCom(result)
|
||||
use RemoteAgentError::*;
|
||||
match result {
|
||||
NS_ERROR_NOT_AVAILABLE => Unavailable,
|
||||
NS_ERROR_LAUNCHED_CHILD_PROCESS => ChildProcess,
|
||||
x => RemoteAgentError::XpCom(x),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use log::*;
|
||||
use nserror::NS_ERROR_ILLEGAL_VALUE;
|
||||
use nsstring::{nsAString, nsString};
|
||||
use xpcom::interfaces::nsIRemoteAgent;
|
||||
use xpcom::RefPtr;
|
||||
|
@ -39,7 +40,15 @@ impl RemoteAgent {
|
|||
let port = addr.port_u16().unwrap_or(DEFAULT_PORT);
|
||||
|
||||
let url = nsString::from(&format!("http://{}:{}/", host, port));
|
||||
unsafe { self.inner.Listen(&*url as &nsAString) }.to_result()?;
|
||||
unsafe { self.inner.Listen(&*url as &nsAString) }
|
||||
.to_result()
|
||||
.map_err(|err| {
|
||||
// TODO(ato): https://bugzil.la/1600139
|
||||
match err {
|
||||
NS_ERROR_ILLEGAL_VALUE => RemoteAgentError::LoopbackRestricted,
|
||||
nsresult => RemoteAgentError::from(nsresult),
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче