Skip to content

Commit

Permalink
fix(app,api): display session error messages in SessionAlert (#4378)
Browse files Browse the repository at this point in the history
Closes #4367
  • Loading branch information
mcous authored Nov 6, 2019
1 parent a8344e9 commit 19d3e00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/src/opentrons/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def _snapshot(self):
payload = {
'state': self.state,
'startTime': self.startTime,
'errors': self.errors,
'lastCommand': last_command
}
return {
Expand Down
7 changes: 6 additions & 1 deletion app/src/components/RunLog/SessionAlert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
import * as React from 'react'
import { useSelector } from 'react-redux'
import { AlertItem } from '@opentrons/components'
import { getSessionError } from '../../robot/selectors'
import type { SessionStatus } from '../../robot'

type Props = {
Expand All @@ -11,6 +13,7 @@ type Props = {

export default function SessionAlert(props: Props) {
const { sessionStatus, className, onResetClick } = props
const sessionError = useSelector(getSessionError)

switch (sessionStatus) {
case 'finished':
Expand Down Expand Up @@ -63,7 +66,9 @@ export default function SessionAlert(props: Props) {
resolving this issue.
</p>
}
/>
>
{sessionError !== null && <p>{sessionError}</p>}
</AlertItem>
)

default:
Expand Down
9 changes: 9 additions & 0 deletions app/src/robot/api-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ export default function client(dispatch) {
clearRunTimerInterval()
}

// both light and full updates may have the errors list
if (apiSession.errors) {
update.errors = apiSession.errors.map(e => ({
timestamp: e.timestamp,
message: e.error.message,
line: e.error.line,
}))
}

// if lastCommand key is present, we're dealing with a light update
if ('lastCommand' in apiSession) {
const lastCommand = apiSession.lastCommand && {
Expand Down
6 changes: 5 additions & 1 deletion app/src/robot/reducer/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ type Request = {
export type SessionState = {
sessionRequest: Request,
state: SessionStatus,
errors: Array<{}>,
errors: Array<{|
timestamp: number,
line: number,
message: string,
|}>,
// TODO(mc, 2018-01-11): command IDs should be strings
protocolCommands: Array<number>,
protocolCommandsById: {
Expand Down
10 changes: 10 additions & 0 deletions app/src/robot/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export const getRunProgress = createSelector(
}
)

export const getSessionError: State => string | null = createSelector(
(state: State) => session(state).runRequest.error,
(state: State) => session(state).errors,
(runError, sessionErrors) => {
if (runError) return runError.message
if (sessionErrors.length > 0) return sessionErrors[0].message
return null
}
)

export function getStartTime(state: State): number | null {
const { startTime, remoteTimeCompensation } = session(state)

Expand Down

0 comments on commit 19d3e00

Please sign in to comment.