Skip to content

Commit

Permalink
Send uncaught saga errors to main process
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Sep 8, 2020
1 parent 6f2c5ba commit 8926116
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
6 changes: 1 addition & 5 deletions src/bootstrap.js
Expand Up @@ -52,11 +52,7 @@ const START =

} catch (e) {
fatal({ stack: e.stack }, `${win.type}.init failed`)

if (ARGS.dev)
ipc.send('wm', 'show')
else
process.crash()
ipc.send('error', e)
}

// eslint-disable-next-line
Expand Down
4 changes: 3 additions & 1 deletion src/browser/tropy.js
Expand Up @@ -856,7 +856,9 @@ export class Tropy extends EventEmitter {
handleUncaughtException(e, win = BrowserWindow.getFocusedWindow()) {
fatal(e)

if (!this.dev) {
if (this.dev) {
win?.show()
} else {
dialog
.alert(win, {
...this.dict.dialog.unhandled,
Expand Down
8 changes: 3 additions & 5 deletions src/sagas/prefs.js
Expand Up @@ -8,13 +8,11 @@ import { shell } from './shell'
import { persist, restore } from './storage'

export function *main() {
let aux
// Delayed import with command registation side-effect!
yield import('../commands/ontology')

try {
// Delayed import with command registation side-effect!
yield import('../commands/ontology')

aux = yield all([
var aux = yield all([
fork(ontology, { max: 2 }),
fork(history),
fork(ipc),
Expand Down
6 changes: 3 additions & 3 deletions src/sagas/project.js
Expand Up @@ -187,14 +187,14 @@ function *close(db, project) {


export function *main() {
// Delayed import with command registation side-effect!
yield import('../commands')

let task
let aux
let crash

try {
// Delayed import with command registation side-effect!
yield import('../commands')

aux = yield all([
fork(ontology, { max: 1 }),
fork(ipc),
Expand Down
14 changes: 5 additions & 9 deletions src/stores/prefs.js
@@ -1,14 +1,9 @@
import {
createStore,
applyMiddleware,
combineReducers,
compose
} from 'redux'

import { ipcRenderer as ipc } from 'electron'
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import thunk from 'redux-thunk'
import createSagaMiddleware from 'redux-saga'
import ARGS from '../args'
import { error } from '../common/log'
import { fatal } from '../common/log'
import { seq, debounce, throttle, log } from '../middleware'

import {
Expand All @@ -31,7 +26,8 @@ const devtools = (ARGS.dev || ARGS.debug) &&
export function create(init = {}) {
let saga = createSagaMiddleware({
onError(e) {
error({ stack: e.stack }, 'unhandled error in saga middleware')
fatal({ stack: e.stack }, 'unhandled error in saga middleware')
ipc.send('error', e)
}
})

Expand Down
14 changes: 5 additions & 9 deletions src/stores/project.js
@@ -1,14 +1,9 @@
import {
createStore,
applyMiddleware,
combineReducers,
compose
} from 'redux'

import { ipcRenderer as ipc } from 'electron'
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import thunk from 'redux-thunk'
import createSagaMiddleware from 'redux-saga'
import ARGS from '../args'
import { error } from '../common/log'
import { fatal } from '../common/log'
import { seq, debounce, throttle, log } from '../middleware'

import {
Expand Down Expand Up @@ -47,7 +42,8 @@ export function create(init = {}) {

let saga = createSagaMiddleware({
onError(e) {
error({ stack: e.stack }, 'unhandled error in saga middleware')
fatal({ stack: e.stack }, 'unhandled error in saga middleware')
ipc.send('error', e)
}
})

Expand Down

0 comments on commit 8926116

Please sign in to comment.