크래시 리포트 — crashReporter와 에러 추적
"프로덕션에서 앱이 죽었는데 원인을 모르면 답이 없다" — 크래시 리포트는 사용자의 앱이 비정상 종료될 때 원인을 수집하는 필수 시스템입니다.
Electron crashReporter
const { crashReporter } = require('electron');
crashReporter.start({
productName: 'MyApp',
submitURL: 'https://your-server.com/crash-reports',
uploadToServer: true,
compress: true,
extra: {
appVersion: app.getVersion(),
platform: process.platform,
arch: process.arch,
},
});
크래시 덤프 위치
// 크래시 덤프 파일 경로
const crashDir = app.getPath('crashDumps');
// macOS: ~/Library/Application Support/앱이름/Crashpad
// Windows: %APPDATA%/앱이름/Crashpad
Sentry 연동
npm install @sentry/electron
// main.js — Sentry 초기화
const Sentry = require('@sentry/electron/main');
Sentry.init({
dsn: 'https://your-dsn@sentry.io/project-id',
release: app.getVersion(),
environment: app.isPackaged ? 'production' : 'development',
});
// 에러에 추가 정보 붙이기
Sentry.setUser({ id: userId, email: userEmail });
Sentry.setTag('os', process.platform);
Sentry.setContext('system', {
memory: process.getSystemMemoryInfo(),
cpu: process.getCPUUsage(),
});
// preload.js — 렌더러용 Sentry
const SentryRenderer = require('@sentry/electron/renderer');
SentryRenderer.init({
dsn: 'https://your-dsn@sentry.io/project-id',
});
수동 에러 보고
try {
riskyOperation();
} catch (error) {
// Sentry에 에러 보고 (앱은 크래시하지 않음)
Sentry.captureException(error, {
extra: {
operation: 'riskyOperation',
input: inputData,
},
});
// 사용자에게 안내
dialog.showErrorBox('오류', '작업 중 문제가 발생했습니다.');
}
렌더러 크래시 복구
// 렌더러 프로세스 크래시 감지
win.webContents.on('render-process-gone', (event, details) => {
log.error('렌더러 크래시:', details.reason, details.exitCode);
Sentry.captureMessage('Renderer process gone', {
level: 'fatal',
extra: { reason: details.reason },
});
// 사용자에게 복구 선택지 제공
const choice = dialog.showMessageBoxSync(mainWindow, {
type: 'error',
title: '오류 발생',
message: '앱에 문제가 발생했습니다.',
buttons: ['재시작', '종료'],
});
if (choice === 0) {
app.relaunch();
}
app.exit(1);
});
면접 포인트 정리
crashReporter는 네이티브 크래시(세그폴트 등)를 수집하는 Electron 내장 기능- Sentry 같은 외부 서비스 연동이 실무에서 필수
- JavaScript 에러와 네이티브 크래시는 별도로 수집해야 함
render-process-gone이벤트로 렌더러 크래시 감지 및 복구
크래시 리포트를 설정했으면, 다음은 다중 윈도우 관리를 알아봅시다.
댓글 로딩 중...