Skip to content

Commit

Permalink
Do not process CLI errors thrown by plots diff
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Nov 29, 2022
1 parent e357450 commit 4be1b8d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
5 changes: 3 additions & 2 deletions extension/src/cli/dvc/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const isDvcError = <
T extends ExperimentsOutput | DataStatusOutput | PlotsOutput
>(
dataOrError: T | DvcError
): dataOrError is DvcError => !!(dataOrError as DvcError).error
): dataOrError is DvcError =>
!!(Object.keys(dataOrError).length === 1 && (dataOrError as DvcError).error)

export const autoRegisteredCommands = {
DATA_STATUS: 'dataStatus',
Expand Down Expand Up @@ -127,7 +128,7 @@ export class DvcReader extends DvcCli {
} catch (error: unknown) {
const msg =
(error as MaybeConsoleError).stderr || (error as Error).message
Logger.error(`${args} failed with ${msg} retrying...`)
Logger.error(`${args} failed with ${msg}`)
return { error: { msg, type: 'Caught error' } }
}
}
Expand Down
16 changes: 14 additions & 2 deletions extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
SectionCollapsed,
PlotSizeNumber
} from '../webview/contract'
import { ExperimentsOutput, PlotsOutput } from '../../cli/dvc/contract'
import {
DvcError,
ExperimentsOutput,
PlotsOutput
} from '../../cli/dvc/contract'
import { Experiments } from '../../experiments'
import { getColorScale, truncateVerticalTitle } from '../vega/util'
import { definedAndNonEmpty, reorderObjectList } from '../../util/array'
Expand All @@ -39,6 +43,7 @@ import {
MultiSourceEncoding,
MultiSourceVariations
} from '../multiSource/collect'
import { isDvcError } from '../../cli/dvc/reader'

export class PlotsModel extends ModelWithPersistence {
private readonly experiments: Experiments
Expand Down Expand Up @@ -104,7 +109,14 @@ export class PlotsModel extends ModelWithPersistence {
return this.removeStaleData()
}

public async transformAndSetPlots(data: PlotsOutput, revs: string[]) {
public async transformAndSetPlots(
data: PlotsOutput | DvcError,
revs: string[]
) {
if (isDvcError(data)) {
return
}

const cliIdToLabel = this.getCLIIdToLabel()

this.fetchedRevs = new Set([
Expand Down
12 changes: 12 additions & 0 deletions extension/src/plots/paths/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,16 @@ describe('PathsModel', () => {
const noChildren = model.getChildren(logsLoss)
expect(noChildren).toStrictEqual([])
})

it('should not provide error as a path when the CLI throws an error', () => {
const model = new PathsModel(mockDvcRoot, buildMockMemento())
model.transformAndSet({
error: {
msg: 'UNEXPECTED ERROR: a strange thing happened',
type: 'Caught Error'
}
})

expect(model.getTerminalNodes()).toStrictEqual([])
})
})
9 changes: 7 additions & 2 deletions extension/src/plots/paths/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
PlotPath,
TemplateOrder
} from './collect'
import { PlotsOutput } from '../../cli/dvc/contract'
import { DvcError, PlotsOutput } from '../../cli/dvc/contract'
import { PathSelectionModel } from '../../path/selection/model'
import { PersistenceKey } from '../../persistence/constants'
import { performSimpleOrderedUpdate } from '../../util/array'
import { MultiSourceEncoding } from '../multiSource/collect'
import { isDvcError } from '../../cli/dvc/reader'

export class PathsModel extends PathSelectionModel<PlotPath> {
private templateOrder: TemplateOrder
Expand All @@ -26,7 +27,11 @@ export class PathsModel extends PathSelectionModel<PlotPath> {
)
}

public transformAndSet(data: PlotsOutput) {
public transformAndSet(data: PlotsOutput | DvcError) {
if (isDvcError(data)) {
return
}

const paths = collectPaths(this.data, data)

this.setNewStatuses(paths)
Expand Down

0 comments on commit 4be1b8d

Please sign in to comment.