1
- import { ERROR_KINDS , DEFINED_ERROR_TYPES } from '../constants'
2
-
3
- import type { ErrorKind } from '../types'
4
1
import type { FailedCommandBySource } from '/app/organisms/ErrorRecoveryFlows/hooks'
2
+ import { DEFINED_ERROR_TYPES , ERROR_KINDS } from '../constants'
3
+ import type { ErrorKind } from '../types'
5
4
6
5
/**
7
6
* Given server-side information about a failed command,
@@ -19,45 +18,45 @@ export function getErrorKind(
19
18
const errorType = failedCommandByRunRecord ?. error ?. errorType
20
19
21
20
if ( Boolean ( errorIsDefined ) ) {
22
- if (
23
- commandType === 'prepareToAspirate' &&
24
- errorType === DEFINED_ERROR_TYPES . OVERPRESSURE
25
- ) {
26
- return ERROR_KINDS . OVERPRESSURE_PREPARE_TO_ASPIRATE
27
- } else if (
28
- ( commandType === 'aspirate' || commandType === 'aspirateInPlace' ) &&
29
- errorType === DEFINED_ERROR_TYPES . OVERPRESSURE
30
- ) {
31
- return ERROR_KINDS . OVERPRESSURE_WHILE_ASPIRATING
32
- } else if (
33
- ( commandType === 'dispense' || commandType === 'dispenseInPlace' ) &&
34
- errorType === DEFINED_ERROR_TYPES . OVERPRESSURE
35
- ) {
36
- return ERROR_KINDS . OVERPRESSURE_WHILE_DISPENSING
37
- } else if (
38
- commandType === 'liquidProbe' &&
39
- errorType === DEFINED_ERROR_TYPES . LIQUID_NOT_FOUND
40
- ) {
41
- return ERROR_KINDS . NO_LIQUID_DETECTED
42
- } else if (
43
- commandType === 'pickUpTip' &&
44
- errorType === DEFINED_ERROR_TYPES . TIP_PHYSICALLY_MISSING
45
- ) {
46
- return ERROR_KINDS . TIP_NOT_DETECTED
47
- } else if (
48
- ( commandType === 'dropTip' || commandType === 'dropTipInPlace' ) &&
49
- errorType === DEFINED_ERROR_TYPES . TIP_PHYSICALLY_ATTACHED
50
- ) {
51
- return ERROR_KINDS . TIP_DROP_FAILED
52
- } else if (
53
- commandType === 'moveLabware' &&
54
- errorType === DEFINED_ERROR_TYPES . GRIPPER_MOVEMENT
55
- ) {
56
- return ERROR_KINDS . GRIPPER_ERROR
57
- } else if ( errorType === DEFINED_ERROR_TYPES . STALL_OR_COLLISION ) {
58
- return ERROR_KINDS . STALL_OR_COLLISION
21
+ switch ( errorType ) {
22
+ case DEFINED_ERROR_TYPES . OVERPRESSURE :
23
+ // The recovery flow varies dependent on the exact failed command.
24
+ switch ( commandType ) {
25
+ case 'prepareToAspirate' :
26
+ return ERROR_KINDS . OVERPRESSURE_PREPARE_TO_ASPIRATE
27
+ case 'aspirate' :
28
+ case 'aspirateInPlace' : {
29
+ return ERROR_KINDS . OVERPRESSURE_WHILE_ASPIRATING
30
+ }
31
+ case 'dispense' :
32
+ case 'dispenseInPlace' :
33
+ case 'blowout' :
34
+ case 'blowOutInPlace' :
35
+ return ERROR_KINDS . OVERPRESSURE_WHILE_DISPENSING
36
+ default : {
37
+ console . error ( `Unhandled overpressure command ${ commandType } ` )
38
+ return ERROR_KINDS . GENERAL_ERROR
39
+ }
40
+ }
41
+ case DEFINED_ERROR_TYPES . LIQUID_NOT_FOUND :
42
+ return ERROR_KINDS . NO_LIQUID_DETECTED
43
+ case DEFINED_ERROR_TYPES . TIP_PHYSICALLY_MISSING :
44
+ return ERROR_KINDS . TIP_NOT_DETECTED
45
+ case DEFINED_ERROR_TYPES . TIP_PHYSICALLY_ATTACHED :
46
+ return ERROR_KINDS . TIP_DROP_FAILED
47
+ case DEFINED_ERROR_TYPES . GRIPPER_MOVEMENT :
48
+ return ERROR_KINDS . GRIPPER_ERROR
49
+ case DEFINED_ERROR_TYPES . STALL_OR_COLLISION :
50
+ return ERROR_KINDS . STALL_OR_COLLISION
51
+ default : {
52
+ console . error ( `Unhandled error type ${ errorType } ` )
53
+ return ERROR_KINDS . GENERAL_ERROR
54
+ }
59
55
}
56
+ } else {
57
+ console . warn (
58
+ `Run status is "awaiting for recovery", but error is not defined: ${ failedCommandByRunRecord } `
59
+ )
60
+ return ERROR_KINDS . GENERAL_ERROR
60
61
}
61
-
62
- return ERROR_KINDS . GENERAL_ERROR
63
62
}
0 commit comments