Skip to content

Commit

Permalink
fix code: PR comment - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Jun 21, 2024
1 parent 54ea899 commit 9a89335
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions client/electron/go_vpn_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {ChildProcessHelper, ProcessTerminatedExitCodeError, ProcessTerminatedSig
import {RoutingDaemon} from './routing_service';
import {VpnTunnel} from './vpn_tunnel';
import {ShadowsocksSessionConfig, TunnelStatus} from '../src/www/app/tunnel';
import {ErrorCode, UnexpectedPluginError} from '../src/www/model/errors';
import {ErrorCode} from '../src/www/model/errors';

const isLinux = platform() === 'linux';
const isWindows = platform() === 'win32';
Expand Down Expand Up @@ -228,7 +228,7 @@ class GoTun2socks {

/**
* Starts tun2socks process, and waits for it to launch successfully.
* Success is confirmed when the phrase "tun2socks started" is detected in the `stdout`.
* Success is confirmed when the phrase "tun2socks running" is detected in the `stdout`.
* Otherwise, an error containing a JSON-formatted message will be thrown.
* @param isUdpEnabled Indicates whether the remote Shadowsocks server supports UDP.
*/
Expand Down
16 changes: 8 additions & 8 deletions client/electron/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ProcessTerminatedSignalError extends Error {
// found).
export class ChildProcessHelper {
private readonly processName: string;
private childProcess?: ChildProcess | null = null;
private childProcess?: ChildProcess;
private waitProcessToExit?: Promise<void>;

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ChildProcessHelper {
const onExit = (code?: number, signal?: string) => {
if (this.childProcess) {
this.childProcess.removeAllListeners();
this.childProcess = null;
this.childProcess = undefined;
} else {
// When listening to both the 'exit' and 'error' events, guard against accidentally
// invoking handler functions multiple times.
Expand All @@ -92,8 +92,8 @@ export class ChildProcessHelper {
}
};

this.childProcess!.stdout?.on('data', data => this.stdOutListener?.(data));
this.childProcess!.stderr?.on('data', (data?: string | Buffer) => {
this.childProcess?.stdout?.on('data', data => this.stdOutListener?.(data));
this.childProcess?.stderr?.on('data', (data?: string | Buffer) => {
if (this.isDebugModeEnabled) {
// This will be captured by Sentry
console.error(`[${this.processName} - STDERR]: ${data}`);
Expand All @@ -104,14 +104,14 @@ export class ChildProcessHelper {
if (this.isDebugModeEnabled) {
// Redirect subprocess output while bypassing the Node console. This makes sure we don't
// send web traffic information to Sentry.
this.childProcess!.stdout?.pipe(process.stdout);
this.childProcess!.stderr?.pipe(process.stderr);
this.childProcess?.stdout?.pipe(process.stdout);
this.childProcess?.stderr?.pipe(process.stderr);
}

// We have to listen for both events: error means the process could not be launched and in that
// case exit will not be invoked.
this.childProcess!.on('error', onExit.bind(this));
this.childProcess!.on('exit', onExit.bind(this));
this.childProcess?.on('error', onExit.bind(this));
this.childProcess?.on('exit', onExit.bind(this));
}));
}

Expand Down
1 change: 1 addition & 0 deletions client/src/tun2socks/outline/electron/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func main() {
}
}()

// This message is used in TypeScript to determine whether tun2socks has been started successfully
logger.Info("tun2socks running...")

osSignals := make(chan os.Signal, 1)
Expand Down
2 changes: 1 addition & 1 deletion client/src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class App {
this.maybeShowAutoConnectDialog();
} catch (e) {
this.updateServerListItem(serverId, {connectionState: ServerConnectionState.DISCONNECTED});
console.error(`could not connect to server ${serverId}: ${e.name}`);
console.error(`could not connect to server ${serverId}: ${e}`);
if (e instanceof errors.SystemConfigurationException) {
if (await this.showConfirmationDialog(this.localize('outline-services-installation-confirmation'))) {
await this.installVpnService();
Expand Down
11 changes: 6 additions & 5 deletions client/src/www/model/platform_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

import {CustomError} from '@outline/infrastructure/custom_error';

//////
// This file defines types and constants corresponding to the backend Go's `platerrors` package.
// It will be used to receive native errors from Go, eventually replacing the older NativeError type.
//////
/**
* @fileoverview This file defines types and constants corresponding to the backend Go's
* `platerrors` package. It will be used to receive native errors from Go, eventually replacing
* the older NativeError type.
*/

/**
* Creates a new {@link PlatformError} instance with the error code set to {@link INTERNAL_ERROR}.
Expand Down Expand Up @@ -56,7 +57,7 @@ function convertRawErrorObjectToPlatformError(rawObj: object): PlatformError {
throw new Error('message is invalid');
}

let options: {details?: ErrorDetails; cause?: Error} = {};
const options: {details?: ErrorDetails; cause?: Error} = {};
if ('details' in rawObj) {
if (typeof rawObj.details !== 'object') {
throw new Error('details is invalid');
Expand Down

0 comments on commit 9a89335

Please sign in to comment.