Skip to content

Commit 4e67d1d

Browse files
feat(overmind-devtools): add error indication
1 parent 5709e24 commit 4e67d1d

File tree

7 files changed

+64
-15
lines changed

7 files changed

+64
-15
lines changed

packages/node_modules/overmind-devtools/src/components/ActionOperator/index.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as styles from './styles'
1313
import * as actionStyles from '../Action/styles'
1414
import * as textStyles from '../../styles/text'
1515
import { css } from 'emotion'
16+
import { colors } from '../../theme'
1617

1718
type Props = {
1819
prevOperator: OperatorType
@@ -39,7 +40,15 @@ const ActionOperator: SFC<Props> = ({ prevOperator, operator, value }) => {
3940
</Path>
4041
<div className={styles.operator}>
4142
<div className={styles.operatorHeader}>
42-
<span className={styles.operatorType}>{operator.type}</span>
43+
<span
44+
className={styles.operatorType}
45+
style={{
46+
backgroundColor: operator.error ? colors.red : null,
47+
color: operator.error ? colors.white : null,
48+
}}
49+
>
50+
{operator.type}
51+
</span>
4352
{operator.name}
4453
{value === undefined ? null : (
4554
<div className={styles.value}>
@@ -51,6 +60,24 @@ const ActionOperator: SFC<Props> = ({ prevOperator, operator, value }) => {
5160
className={styles.operatorBody}
5261
onClick={(event) => event.stopPropagation()}
5362
>
63+
{operator.error ? (
64+
<div className={styles.operatorItem}>
65+
<span
66+
className={css(
67+
textStyles.description,
68+
textStyles.red,
69+
textStyles.monospace
70+
)}
71+
>
72+
error
73+
</span>
74+
<span
75+
className={css(textStyles.description, textStyles.monospace)}
76+
>
77+
{operator.error}
78+
</span>
79+
</div>
80+
) : null}
5481
{operator.events.map((event, index) => {
5582
if (event.type === EventType.Effect) {
5683
const effect = event.data as Effect

packages/node_modules/overmind-devtools/src/overmind/operators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export const updateOperator: Operator<EndOperatorMessage> = action(
253253
operator.isAsync = operatorData.isAsync
254254
operator.isRunning = false
255255
operator.result = operatorData.result
256+
operator.error = operatorData.error
256257
}
257258
)
258259

packages/node_modules/overmind-devtools/src/overmind/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type Operator = {
6767
operatorId: number
6868
path: string[]
6969
result?: any
70+
error?: string
7071
}
7172

7273
export type Action = {
@@ -262,6 +263,7 @@ export type EndOperatorMessage = AppMessage<{
262263
type: string
263264
isAsync: boolean
264265
result: any
266+
error?: string
265267
}>
266268

267269
export type AsyncOperatorMessage = AppMessage<{

packages/node_modules/overmind-devtools/src/styles/text.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ export const white = css({
55
color: colors.white,
66
})
77

8+
export const red = css({
9+
color: colors.red,
10+
})
11+
812
export const purple = css({
913
color: colors.purple,
1014
})

packages/node_modules/overmind/src/index.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,20 +536,32 @@ export class Overmind<ThisConfig extends IConfiguration>
536536

537537
const scopedValue = this.scopeValue(value, mutationTree)
538538
const context = this.createContext(scopedValue, execution, mutationTree)
539-
const result = action(context, scopedValue)
540539

541-
this.eventHub.emit(EventType.OPERATOR_END, {
542-
...execution,
543-
isAsync: result instanceof Promise,
544-
result: undefined,
545-
})
546-
this.eventHub.emit(EventType.ACTION_END, execution)
540+
try {
541+
const result = action(context, scopedValue)
547542

548-
if (result) {
549-
await result
550-
}
543+
this.eventHub.emit(EventType.OPERATOR_END, {
544+
...execution,
545+
isAsync: result instanceof Promise,
546+
result: undefined,
547+
})
548+
this.eventHub.emit(EventType.ACTION_END, execution)
551549

552-
return this.mode.mode === MODE_TEST ? execution : undefined
550+
if (result) {
551+
await result
552+
}
553+
554+
return this.mode.mode === MODE_TEST ? execution : undefined
555+
} catch (err) {
556+
this.eventHub.emit(EventType.OPERATOR_END, {
557+
...execution,
558+
isAsync: false,
559+
result: undefined,
560+
error: err.message,
561+
})
562+
this.eventHub.emit(EventType.ACTION_END, execution)
563+
throw err
564+
}
553565
}
554566
}
555567

@@ -794,6 +806,7 @@ export class Overmind<ThisConfig extends IConfiguration>
794806
type: 're_init',
795807
data: {
796808
state: proxyStateTree.sourceState,
809+
actions: getActionPaths(configuration.actions),
797810
},
798811
})
799812
}

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type Execution = {
6868
}
6969
getMutationTree(): IMutationTree<any>
7070
value?: any
71+
error?: string
7172
}
7273

7374
export interface Events {

packages/node_modules/overmind/src/operator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function startDebugOperator(type, arg, context) {
1717
})
1818
}
1919

20-
export function stopDebugOperator(context, value) {
20+
export function stopDebugOperator(context, value, error?) {
2121
if (IS_PRODUCTION) {
2222
return
2323
}
@@ -39,6 +39,7 @@ export function stopDebugOperator(context, value) {
3939
...context.execution,
4040
result: safeValue(value),
4141
isAsync: false,
42+
error: error ? error.message : undefined,
4243
})
4344
}
4445
}
@@ -136,7 +137,7 @@ export function createOperator<ThisConfig extends IConfiguration>(
136137
}
137138
)
138139
} catch (error) {
139-
stopDebugOperator(context, context.value)
140+
stopDebugOperator(context, context.value, error)
140141
next(error, createContext(context, context.value))
141142
}
142143
}
@@ -202,7 +203,7 @@ export function createMutationOperator<ThisConfig extends IConfiguration>(
202203
}
203204
)
204205
} catch (error) {
205-
stopDebugOperator(context, context.value)
206+
stopDebugOperator(context, context.value, error)
206207
next(error, createContext(context, context.value))
207208
}
208209
}

0 commit comments

Comments
 (0)