Commit 4119a744 authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

fixup! TB 40933: Add tor-launcher functionality

TB 43636: Distinguish between bootstrap errors and TorProvider
initialisation errors.
parent 7dd37f1d
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -54,9 +54,7 @@ export class TorBootstrapRequest {
      }
      case lazy.TorProviderTopics.BootstrapError: {
        log.info("TorBootstrapRequest: observerd TorBootstrapError", obj);
        const error = new Error(obj.summary);
        Object.assign(error, obj);
        this.#stop(error);
        this.#stop(obj);
        break;
      }
    }
+6 −4
Original line number Diff line number Diff line
@@ -6,7 +6,10 @@ import { clearTimeout, setTimeout } from "resource://gre/modules/Timer.sys.mjs";

import { TorLauncherUtil } from "resource://gre/modules/TorLauncherUtil.sys.mjs";
import { TorParsers } from "resource://gre/modules/TorParsers.sys.mjs";
import { TorProviderTopics } from "resource://gre/modules/TorProviderBuilder.sys.mjs";
import {
  TorBootstrapError,
  TorProviderTopics,
} from "resource://gre/modules/TorProviderBuilder.sys.mjs";

const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
@@ -996,12 +999,11 @@ export class TorProvider {
      // anymore, since the first error eligible for notification will as a
      // matter of fact cancel the bootstrap.
      Services.obs.notifyObservers(
        {
        new TorBootstrapError({
          phase: statusObj.TAG,
          reason: statusObj.REASON,
          summary: statusObj.SUMMARY,
          warning: statusObj.WARNING,
        },
        }),
        TorProviderTopics.BootstrapError
      );
    }
+42 −1
Original line number Diff line number Diff line
@@ -18,6 +18,41 @@ export const TorProviderTopics = Object.freeze({
  CircuitCredentialsMatched: "TorCircuitCredentialsMatched",
});

/**
 * Wrapper error class for errors raised during TorProvider.init.
 */
export class TorProviderInitError extends Error {
  /**
   * Create a new instance.
   *
   * @param {any} error - The raised error that we want to wrap.
   */
  constructor(error) {
    super(error?.message, { cause: error });
    this.name = "TorProviderInitError";
  }
}

/**
 * Bootstrap errors raised by the TorProvider.
 */
export class TorBootstrapError extends Error {
  /**
   * Create a new instance.
   *
   * @param {object} details - Details about the error.
   * @param {string} details.summary - A summary of the error.
   * @param {string} details.phase - The bootstrap phase when the error occured.
   * @param {string} details.reason - The reason for the bootsrap failure.
   */
  constructor(details) {
    super(details.summary);
    this.name = "TorBootstrapError";
    this.phase = details.phase;
    this.reason = details.reason;
  }
}

export const TorProviders = Object.freeze({
  none: 0,
  tor: 1,
@@ -178,7 +213,13 @@ export class TorProviderBuilder {
      (await oldProvider)?.uninit();
    } catch {}
    const provider = new lazy.TorProvider();
    try {
      await provider.init();
    } catch (error) {
      // Wrap in an error type for callers to know whether the error comes from
      // initialisation or something else.
      throw new TorProviderInitError(error);
    }
    return provider;
  }