Skip to content
Snippets Groups Projects
Verified Commit 8d41f191 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Bug 40933: Add tor-launcher functionality

Do not localize errors in TorProcess, but keep it only as a pure backend
file. Moreover, the localized errors would be only shown in the console.
Instead, report an error code to let them bubble up to the
TorProviderBuilder, where we show them in the "Restart Tor" prompt.
parent 76623561
Branches
Tags
1 merge request!968Draft: Bug 42479: Improve TorConnect error handling
......@@ -376,9 +376,12 @@ export const TorLauncherUtil = Object.freeze({
* @param {boolean} initError If we could connect to the control port at
* least once and we are showing this prompt because the tor process exited
* suddenly, we will display a different message
* @param {Error?=} error The error that caused Tor not to launch. If it has a
* code, we will try to translate it, otherwise we will show the message
* (if not empty).
* @returns {boolean} true if the user asked to restart tor
*/
showRestartPrompt(initError) {
showRestartPrompt(initError, error = null) {
let s;
if (initError) {
const key = "tor_exited_during_startup";
......@@ -390,6 +393,15 @@ export const TorLauncherUtil = Object.freeze({
"\n\n" +
this.getLocalizedString("tor_exited2");
}
if (error) {
if (error.code && this.getLocalizedString(error.code) !== error.code) {
s += "\n\n" + this.getLocalizedString(error.code);
} else if (error.message) {
s += `\n\n${error.message}`;
}
}
const defaultBtnLabel = this.getLocalizedString("restart_tor");
let cancelBtnLabel = "OK";
try {
......
......@@ -201,46 +201,51 @@ export class TorProcess {
"toronionauthdir",
true
);
let detailsKey;
let errorCode;
if (!this.#exeFile) {
detailsKey = "tor_missing";
errorCode = "tor_missing";
} else if (!torrcFile) {
detailsKey = "torrc_missing";
errorCode = "torrc_missing";
} else if (!this.#dataDir) {
detailsKey = "datadir_missing";
errorCode = "datadir_missing";
} else if (!onionAuthDir) {
detailsKey = "onionauthdir_missing";
}
if (detailsKey) {
const details = lazy.TorLauncherUtil.getLocalizedString(detailsKey);
const key = "unable_to_start_tor";
const err = lazy.TorLauncherUtil.getFormattedLocalizedString(
key,
[details],
1
);
throw new Error(err);
errorCode = "onionauthdir_missing";
}
if (errorCode) {
const error = new Error(`An essential file is missing (${errorCode})`);
error.code = errorCode;
throw error;
}
this.#args = [
"-f",
torrcFile.path,
"DataDirectory",
this.#dataDir.path,
"ClientOnionAuthDir",
onionAuthDir.path,
];
// TODO: Create this starting from pt_config.json (tor-browser#42357).
const torrcDefaultsFile = lazy.TorLauncherUtil.getTorFile(
"torrc-defaults",
false
);
if (torrcDefaultsFile) {
this.#args.push("--defaults-torrc", torrcDefaultsFile.path);
// The geoip and geoip6 files are in the same directory as torrc-defaults.
const geoipFile = torrcDefaultsFile.clone();
geoipFile.leafName = "geoip";
this.#args.push("GeoIPFile", geoipFile.path);
const geoip6File = torrcDefaultsFile.clone();
geoip6File.leafName = "geoip6";
this.#args = [];
if (torrcDefaultsFile) {
this.#args.push("--defaults-torrc", torrcDefaultsFile.path);
}
this.#args.push("-f", torrcFile.path);
this.#args.push("DataDirectory", this.#dataDir.path);
this.#args.push("ClientOnionAuthDir", onionAuthDir.path);
this.#args.push("GeoIPFile", geoipFile.path);
this.#args.push("GeoIPv6File", geoip6File.path);
} else {
logger.warn(
"torrc-defaults not found, some functionalities will be disabled."
);
}
}
/**
......
......@@ -148,6 +148,7 @@ export class TorProviderBuilder {
return;
}
let running = false;
let error;
try {
const provider = await this.#provider;
// The initialization might have succeeded, but so far we have ignored any
......@@ -155,14 +156,17 @@ export class TorProviderBuilder {
// provider has been initialized successfully, but the UI was not ready
// yet.
running = provider.isRunning;
} catch {
} catch (e) {
// Not even initialized, running is already false.
error = e;
}
while (!running && lazy.TorLauncherUtil.showRestartPrompt(true)) {
while (!running && lazy.TorLauncherUtil.showRestartPrompt(true, error)) {
try {
await this.#initTorProvider();
running = true;
} catch {}
} catch (e) {
error = e;
}
}
// The user might have canceled the restart, but at this point the UI is
// ready in any case.
......@@ -176,11 +180,14 @@ export class TorProviderBuilder {
);
return;
}
while (lazy.TorLauncherUtil.showRestartPrompt(false)) {
let error = null;
while (lazy.TorLauncherUtil.showRestartPrompt(false, error)) {
try {
await this.#initTorProvider();
break;
} catch {}
} catch (e) {
error = e;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment