Skip to content

Commit

Permalink
fix: getCrashesDirectory is documented as API now (#234)
Browse files Browse the repository at this point in the history
* fix: getCrashesDirectory is documented as API now

* chore: fixup TS errors from electron upgrade

* chore: fix lint

Co-authored-by: Daniel Griesser <daniel.griesser.86@gmail.com>
  • Loading branch information
MarshallOfSound and HazAT authored Jul 3, 2020
1 parent c6c4e44 commit 8096dcb
Show file tree
Hide file tree
Showing 5 changed files with 386 additions and 41 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"cross-env": "^5.2.0",
"electron": "5.0.12",
"electron": "8.3.0",
"electron-download": "^4.1.1",
"electron-mocha": "^6.0.4",
"express": "^4.16.2",
Expand Down
26 changes: 7 additions & 19 deletions src/main/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import { Store } from './store';
import { NetTransport } from './transports/net';
import { MinidumpUploader } from './uploader';

/** Patch to access internal CrashReporter functionality. */
interface CrashReporterExt {
/** Gets the crashes directory */
getCrashesDirectory(): string;
}

/** Gets the path to the Sentry cache directory. */
function getCachePath(): string {
return join(app.getPath('userData'), 'sentry');
Expand All @@ -40,7 +34,9 @@ export async function isAppReady(): Promise<boolean> {
app.isReady() ||
// tslint:disable-next-line: no-promise-as-boolean
new Promise<boolean>(resolve => {
app.once('ready', resolve);
app.once('ready', () => {
resolve(true);
});
})
);
}
Expand Down Expand Up @@ -200,11 +196,10 @@ export class MainBackend extends BaseBackend<ElectronOptions> implements CommonB
uploadToServer: false,
});

// The crashReporter has an undocumented method to retrieve the directory
// The crashReporter has a method to retrieve the directory
// it uses to store minidumps in. The structure in this directory depends
// on the crash library being used (Crashpad or Breakpad).
const reporter: CrashReporterExt = crashReporter as any;
const crashesDirectory = reporter.getCrashesDirectory();
const crashesDirectory = crashReporter.getCrashesDirectory();

this._uploader = new MinidumpUploader(dsn, crashesDirectory, getCachePath());

Expand Down Expand Up @@ -245,18 +240,11 @@ export class MainBackend extends BaseBackend<ElectronOptions> implements CommonB

/** Installs IPC handlers to receive events and metadata from renderers. */
private _installIPC(): void {
ipcMain.on(IPC_PING, (event: Electron.Event) => {
ipcMain.on(IPC_PING, (event: Electron.IpcMainEvent) => {
event.sender.send(IPC_PING);
});

ipcMain.on(IPC_EVENT, (ipc: Electron.Event, jsonEvent: string) => {
let event: Event;
try {
event = JSON.parse(jsonEvent) as Event;
} catch {
console.warn('sentry-electron received an invalid IPC_EVENT message');
return;
}
ipcMain.on(IPC_EVENT, (ipc: Electron.IpcMainEvent, event: Event) => {
event.extra = {
...this._getRendererExtra(ipc.sender),
...event.extra,
Expand Down
4 changes: 2 additions & 2 deletions src/main/integrations/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class Electron implements Integration {
* Hooks into the Electron EventEmitter to capture breadcrumbs for the
* specified events.
*/
private _instrumentBreadcrumbs(category: string, emitter: Electron.EventEmitter, events: string[] = []): void {
private _instrumentBreadcrumbs(category: string, emitter: NodeJS.EventEmitter, events: string[] = []): void {
type Emit = (event: string, ...args: any[]) => boolean;
const emit = emitter.emit.bind(emitter) as Emit;

emitter.emit = (event, ...args) => {
emitter.emit = (event: string, ...args) => {
if (events.length === 0 || events.indexOf(event) > -1) {
const breadcrumb = {
category: 'electron',
Expand Down
7 changes: 5 additions & 2 deletions src/main/transports/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NetTransport extends Transports.BaseTransport {
await isAppReady();
return this._buffer.add(
new Promise<Response>((resolve, reject) => {
const req = net.request(this._getRequestOptions());
const req = net.request(this._getRequestOptions() as Electron.ClientRequestConstructorOptions);
req.on('error', reject);
req.on('response', (res: Electron.IncomingMessage) => {
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
Expand All @@ -35,7 +35,10 @@ export class NetTransport extends Transports.BaseTransport {
} else {
// tslint:disable:no-unsafe-any
if (res.headers && res.headers['x-sentry-error']) {
const reason = res.headers['x-sentry-error'];
let reason: string | string[] = res.headers['x-sentry-error'];
if (Array.isArray(reason)) {
reason = reason.join(', ');
}
// tslint:enable:no-unsafe-any
reject(new SentryError(`HTTP Error (${res.statusCode}): ${reason}`));
} else {
Expand Down
Loading

0 comments on commit 8096dcb

Please sign in to comment.