Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getCrashesDirectory is documented as API now #234

Merged
merged 4 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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