Skip to content

Commit

Permalink
replace assert with console.assert
Browse files Browse the repository at this point in the history
  • Loading branch information
shlokamin committed Feb 22, 2024
1 parent f1256cd commit bd72700
Show file tree
Hide file tree
Showing 37 changed files with 102 additions and 103 deletions.
2 changes: 1 addition & 1 deletion components/src/interaction-enhancers/useOnClickOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useOnClickOutside = <E extends Element>(
const handleClickOutside = (event: MouseEvent): void => {
const clickedElem = event.target

assert(
console.assert(
clickedElem instanceof Node,
'expected clicked element to be Node - something went wrong in onClickOutside hook'
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import * as React from 'react'
import { DropTarget, DropTargetConnector, DropTargetMonitor } from 'react-dnd'
import cx from 'classnames'
Expand Down Expand Up @@ -175,7 +175,7 @@ const slotTarget = {
canDrop: (props: SlotControlsProps, monitor: DropTargetMonitor) => {
const draggedItem = monitor.getItem()
const draggedDef = draggedItem?.labwareOnDeck?.def
assert(draggedDef, 'no labware def of dragged item, expected it on drop')
console.assert(draggedDef, 'no labware def of dragged item, expected it on drop')

if (draggedDef != null) {
const isCustomLabware = getLabwareIsCustom(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { connect } from 'react-redux'
Expand Down Expand Up @@ -174,7 +174,7 @@ const slotTarget = {
const draggedItem = monitor.getItem()
const draggedDef = draggedItem?.labwareOnDeck?.def
const moduleType = props.moduleType
assert(draggedDef, 'no labware def of dragged item, expected it on drop')
console.assert(draggedDef, 'no labware def of dragged item, expected it on drop')

if (moduleType != null && draggedDef != null) {
// this is a module slot, prevent drop if the dragged labware is not compatible
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import assert from 'assert'

import { useDispatch, useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
import cx from 'classnames'
Expand All @@ -26,13 +26,13 @@ export function LabwareDetailsCard(): JSX.Element {
? getLabwareDisplayName(labwareEntities[labwareId].def)
: null

assert(
console.assert(
labwareId,
'Expected labware id to exist in connected labware details card'
)

const renameLabware = (name: string): void => {
assert(
console.assert(
labwareId,
'renameLabware in LabwareDetailsCard expected a labwareId'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Controller, useForm } from 'react-hook-form'
import isEmpty from 'lodash/isEmpty'
import { useTranslation } from 'react-i18next'
import { useSelector, useDispatch } from 'react-redux'
import assert from 'assert'

import * as wellContentsSelectors from '../../top-selectors/well-contents'
import * as fieldProcessors from '../../steplist/fieldLevel/processing'
import {
Expand Down Expand Up @@ -118,23 +118,23 @@ export const LiquidPlacementForm = (): JSX.Element | null => {
const handleSaveForm = (values: LiquidPlacementFormValues): void => {
const volume = Number(values.volume)
const { selectedLiquidId } = values
assert(
console.assert(
labwareId != null,
'when saving liquid placement form, expected a selected labware ID'
)
assert(
console.assert(
selectedWells && selectedWells.length > 0,
`when saving liquid placement form, expected selected wells to be array with length > 0 but got ${String(
selectedWells
)}`
)
assert(
console.assert(
selectedLiquidId != null,
`when saving liquid placement form, expected selectedLiquidId to be non-nullsy but got ${String(
selectedLiquidId
)}`
)
assert(
console.assert(
volume > 0,
`when saving liquid placement form, expected volume > 0, got ${volume}`
)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/components/LiquidPlacementModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import assert from 'assert'

import { useDispatch, useSelector } from 'react-redux'
import cx from 'classnames'
import isEmpty from 'lodash/isEmpty'
Expand Down Expand Up @@ -33,7 +33,7 @@ export function LiquidPlacementModal(): JSX.Element {
const liquidNamesById = useSelector(selectors.getLiquidNamesById)
const liquidDisplayColors = useSelector(selectors.getLiquidDisplayColors)
if (labwareId == null) {
assert(
console.assert(
false,
'LiquidPlacementModal: No labware is selected, and no labwareId was given to LiquidPlacementModal'
)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/components/LiquidsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import assert from 'assert'


import * as labwareIngredActions from '../../labware-ingred/actions'
import { selectors as labwareIngredSelectors } from '../../labware-ingred/selectors'
Expand Down Expand Up @@ -45,7 +45,7 @@ export function LiquidsPage(): JSX.Element {
})
)
}
assert(
console.assert(
!(liquidGroupId && !selectedIngredFields),
`Expected selected liquid group "${String(
liquidGroupId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import {
DEFAULT_MM_FROM_BOTTOM_ASPIRATE,
DEFAULT_MM_FROM_BOTTOM_DISPENSE,
Expand Down Expand Up @@ -35,7 +35,7 @@ export function getDefaultMmFromBottom(args: {

default:
// touch tip fields
assert(
console.assert(
getIsTouchTipField(name),
`getDefaultMmFromBottom fn does not know what to do with field ${name}`
)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/components/alerts/Alerts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import assert from 'assert'

import { useTranslation } from 'react-i18next'
import { useSelector, useDispatch } from 'react-redux'
import * as timelineWarningSelectors from '../../top-selectors/timelineWarnings'
Expand Down Expand Up @@ -116,7 +116,7 @@ const AlertsComponent = (props: Props): JSX.Element => {
}
}
const makeHandleCloseWarning = (dismissId?: string | null) => () => {
assert(dismissId, 'expected dismissId, Alert cannot dismiss warning')
console.assert(dismissId, 'expected dismissId, Alert cannot dismiss warning')
if (dismissId) {
dismissWarning(dismissId)
}
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/components/labware/BrowsableLabware.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import * as React from 'react'
import { useSelector } from 'react-redux'
import reduce from 'lodash/reduce'
Expand All @@ -23,7 +23,7 @@ export function BrowsableLabware(props: Props): JSX.Element | null {
const { definition, ingredNames, wellContents } = props
const liquidDisplayColors = useSelector(selectors.getLiquidDisplayColors)
if (!definition) {
assert(definition, 'BrowseLabwareModal expected definition')
console.assert(definition, 'BrowseLabwareModal expected definition')
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import * as React from 'react'
import cx from 'classnames'
import { useDispatch, useSelector } from 'react-redux'
Expand Down Expand Up @@ -30,7 +30,7 @@ export const BrowseLabwareModal = (): JSX.Element | null => {
: null

if (!definition) {
assert(definition, 'BrowseLabwareModal expected definition')
console.assert(definition, 'BrowseLabwareModal expected definition')
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import assert from 'assert'

import { useForm } from 'react-hook-form'
import { yupResolver } from '@hookform/resolvers/yup'
import reduce from 'lodash/reduce'
Expand Down Expand Up @@ -354,7 +354,7 @@ export const FilePipettesModal = (props: Props): JSX.Element => {
const pipettes = reduce<FormPipettesByMount, PipetteFieldsData[]>(
values.pipettesByMount,
(acc, formPipette: FormPipette, mount): PipetteFieldsData[] => {
assert(mount === 'left' || mount === 'right', `invalid mount: ${mount}`) // this is mostly for flow
console.assert(mount === 'left' || mount === 'right', `invalid mount: ${mount}`) // this is mostly for flow
// @ts-expect-error(sa, 2021-6-21): TODO validate that pipette names coming from the modal are actually valid pipette names on PipetteName type
return formPipette &&
formPipette.pipetteName &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Trans, useTranslation } from 'react-i18next'
import assert from 'assert'

import styles from './modalContents.module.css'
import { FileUploadMessage } from '../../../load-file'
import type { ModalContents } from './types'
Expand Down Expand Up @@ -191,7 +191,7 @@ export function useModalContents(
t,
})
default: {
assert(
console.assert(
false,
`invalid messageKey ${uploadResponse.messageKey} specified for modal`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useTranslation } from 'react-i18next'
import assert from 'assert'

import cx from 'classnames'
import { AlertModal, OutlineButton, ButtonProps } from '@opentrons/components'
import modalStyles from '../modal.module.css'
Expand Down Expand Up @@ -80,7 +80,7 @@ const MessageBody = (props: {
</>
)
}
assert(false, `MessageBody got unhandled messageType: ${message.messageType}`)
console.assert(false, `MessageBody got unhandled messageType: ${message.messageType}`)
return null
}

Expand All @@ -107,7 +107,7 @@ export const LabwareUploadMessageModal = (): JSX.Element | null => {
})
)
} else {
assert(
console.assert(
false,
`labware def should only be overwritten when messageType is ASK_FOR_LABWARE_OVERWRITE. Got ${String(
message?.messageType
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import type {
import type { Selector } from '../../types'

// TODO: BC: 2018-02-21 uncomment this assert, causes test failures
// assert(!isEmpty(process.env.OT_PD_VERSION), 'Could not find application version!')
// console.assert(!isEmpty(process.env.OT_PD_VERSION), 'Could not find application version!')
if (isEmpty(process.env.OT_PD_VERSION))
console.warn('Could not find application version!')
const applicationVersion: string = process.env.OT_PD_VERSION || ''
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/labware-defs/__mocks__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// replace webpack-specific require.context with Node-based glob in tests
import assert from 'assert'

import { vi } from 'vitest'
import path from 'path'
import glob from 'glob'
Expand All @@ -16,7 +16,7 @@ const allLabware: LabwareDefByDefURI = glob
.map(require)
.filter(d => d.metadata.displayCategory !== 'trash')
.reduce((acc, d) => ({ ...acc, [getLabwareDefURI(d)]: d }), {})
assert(
console.assert(
Object.keys(allLabware).length > 0,
`no labware fixtures found, is the path correct? ${LABWARE_FIXTURE_PATTERN}`
)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/labware-defs/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import Ajv from 'ajv'
import isEqual from 'lodash/isEqual'
import flatten from 'lodash/flatten'
Expand Down Expand Up @@ -186,7 +186,7 @@ const _createCustomLabwareDef: (
...defsMatchingCustomLoadName,
...defsMatchingCustomDisplayName,
]
assert(
console.assert(
uniqBy(matchingDefs, getLabwareDefURI).length === 1,
'expected exactly 1 matching labware def to ask to overwrite'
)
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/labware-ingred/actions/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import { getIsTiprack } from '@opentrons/shared-data'
import { uuid } from '../../utils'
import { selectors as labwareDefSelectors } from '../../labware-defs'
Expand Down Expand Up @@ -116,7 +116,7 @@ export const duplicateLabware: (
const templateLabwareDefURI = stepFormSelectors.getLabwareEntities(state)[
templateLabwareId
].labwareDefURI
assert(
console.assert(
templateLabwareDefURI,
`no labwareDefURI for labware ${templateLabwareId}, cannot run duplicateLabware thunk`
)
Expand Down
8 changes: 4 additions & 4 deletions protocol-designer/src/load-file/migration/1_1_0.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import isUndefined from 'lodash/isUndefined'
import mapValues from 'lodash/mapValues'
import omit from 'lodash/omit'
Expand Down Expand Up @@ -77,12 +77,12 @@ function getPipetteCapacityLegacy(
return Math.min(specs.maxVolume, tiprackDef.metadata.tipVolume)
}

assert(specs, `Expected spec for pipette ${JSON.stringify(pipette)}`)
assert(
console.assert(specs, `Expected spec for pipette ${JSON.stringify(pipette)}`)
console.assert(
tiprackDef,
`expected tiprack def for pipette ${JSON.stringify(pipette)}`
)
assert(
console.assert(
tiprackDef?.metadata?.tipVolume,
`expected tiprack volume for tiprack def ${JSON.stringify(
tiprackDef?.metadata || 'undefined'
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/persist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get from 'lodash/get'
import assert from 'assert'

import { Store } from 'redux'
import { dismissedHintsPersist } from './tutorial/reducers'
export interface RehydratePersistedAction {
Expand All @@ -22,7 +22,7 @@ export const getLocalStorageItem = (path: string): unknown => {
}
// The `path` should match where the reducer lives in the Redux state tree
export const _rehydrate = (path: string): any => {
assert(
console.assert(
PERSISTED_PATHS.includes(path),
`Path "${path}" is missing from PERSISTED_PATHS! The changes to this reducer will not be persisted.`
)
Expand Down
6 changes: 3 additions & 3 deletions protocol-designer/src/pipettes/pipetteData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'assert'

import { DropdownOption } from '../../../components/lib/forms/DropdownField.d'
import {
getPipetteNameSpecs,
Expand Down Expand Up @@ -42,7 +42,7 @@ export function getPipetteCapacity(pipetteEntity: PipetteEntity): number {
return Math.min(spec.maxVolume, getTiprackVolume(tiprackDef))
}

assert(
console.assert(
false,
`Expected spec and tiprack def for pipette ${
pipetteEntity ? pipetteEntity.id : '???'
Expand All @@ -57,7 +57,7 @@ export function getMinPipetteVolume(pipetteEntity: PipetteEntity): number {
return spec.minVolume
}

assert(
console.assert(
false,
`Expected spec for pipette ${pipetteEntity ? pipetteEntity.id : '???'}`
)
Expand Down
Loading

0 comments on commit bd72700

Please sign in to comment.