Skip to content

Commit e6e62d5

Browse files
authored
Do not process CLI errors thrown by plots diff (#2852)
1 parent 9397d1d commit e6e62d5

File tree

7 files changed

+48
-15
lines changed

7 files changed

+48
-15
lines changed

extension/src/cli/dvc/contract.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ export interface ExperimentsOutput {
9393
export interface PlotsOutput {
9494
[path: string]: Plot[]
9595
}
96+
97+
export type PlotsOutputOrError = PlotsOutput | DvcError

extension/src/cli/dvc/reader.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
DataStatusOutput,
1414
DvcError,
1515
ExperimentsOutput,
16-
PlotsOutput
16+
PlotsOutput,
17+
PlotsOutputOrError
1718
} from './contract'
1819
import { getOptions } from './options'
1920
import { typeCheckCommands } from '..'
@@ -29,7 +30,8 @@ export const isDvcError = <
2930
T extends ExperimentsOutput | DataStatusOutput | PlotsOutput
3031
>(
3132
dataOrError: T | DvcError
32-
): dataOrError is DvcError => !!(dataOrError as DvcError).error
33+
): dataOrError is DvcError =>
34+
!!(Object.keys(dataOrError).length === 1 && (dataOrError as DvcError).error)
3335

3436
export const autoRegisteredCommands = {
3537
DATA_STATUS: 'dataStatus',
@@ -80,7 +82,7 @@ export class DvcReader extends DvcCli {
8082
public plotsDiff(
8183
cwd: string,
8284
...revisions: string[]
83-
): Promise<PlotsOutput | DvcError> {
85+
): Promise<PlotsOutputOrError> {
8486
return this.readProcessJson<PlotsOutput>(
8587
cwd,
8688
Command.PLOTS,
@@ -127,7 +129,7 @@ export class DvcReader extends DvcCli {
127129
} catch (error: unknown) {
128130
const msg =
129131
(error as MaybeConsoleError).stderr || (error as Error).message
130-
Logger.error(`${args} failed with ${msg} retrying...`)
132+
Logger.error(`${args} failed with ${msg}`)
131133
return { error: { msg, type: 'Caught error' } }
132134
}
133135
}

extension/src/data/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
} from '../fileSystem/watcher'
88
import { ProcessManager } from '../processManager'
99
import { InternalCommands } from '../commands/internal'
10-
import { ExperimentsOutput, PlotsOutput } from '../cli/dvc/contract'
10+
import { ExperimentsOutput, PlotsOutputOrError } from '../cli/dvc/contract'
1111
import { definedAndNonEmpty, sameContents, uniqueValues } from '../util/array'
1212
import { DeferredDisposable } from '../class/deferred'
1313

1414
export abstract class BaseData<
15-
T extends { data: PlotsOutput; revs: string[] } | ExperimentsOutput
15+
T extends { data: PlotsOutputOrError; revs: string[] } | ExperimentsOutput
1616
> extends DeferredDisposable {
1717
public readonly onDidUpdate: Event<T>
1818

extension/src/plots/data/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { EventEmitter } from 'vscode'
2-
import { PlotsOutput } from '../../cli/dvc/contract'
2+
import { PlotsOutputOrError } from '../../cli/dvc/contract'
3+
import { isDvcError } from '../../cli/dvc/reader'
34
import { AvailableCommands, InternalCommands } from '../../commands/internal'
45
import { BaseData } from '../../data'
56
import {
@@ -9,7 +10,10 @@ import {
910
} from '../../util/array'
1011
import { PlotsModel } from '../model'
1112

12-
export class PlotsData extends BaseData<{ data: PlotsOutput; revs: string[] }> {
13+
export class PlotsData extends BaseData<{
14+
data: PlotsOutputOrError
15+
revs: string[]
16+
}> {
1317
private readonly model: PlotsModel
1418

1519
constructor(
@@ -49,7 +53,7 @@ export class PlotsData extends BaseData<{ data: PlotsOutput; revs: string[] }> {
4953
}
5054

5155
const args = this.getArgs(revs)
52-
const data = await this.internalCommands.executeCommand<PlotsOutput>(
56+
const data = await this.internalCommands.executeCommand<PlotsOutputOrError>(
5357
AvailableCommands.PLOTS_DIFF,
5458
this.dvcRoot,
5559
...args
@@ -66,8 +70,11 @@ export class PlotsData extends BaseData<{ data: PlotsOutput; revs: string[] }> {
6670
return this.processManager.run('update')
6771
}
6872

69-
public collectFiles({ data }: { data: PlotsOutput }) {
70-
return Object.keys(data)
73+
public collectFiles({ data }: { data: PlotsOutputOrError }) {
74+
if (isDvcError(data)) {
75+
return this.collectedFiles
76+
}
77+
return [...Object.keys(data), ...this.collectedFiles]
7178
}
7279

7380
private getArgs(revs: string[]) {

extension/src/plots/model/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
SectionCollapsed,
2626
PlotSizeNumber
2727
} from '../webview/contract'
28-
import { ExperimentsOutput, PlotsOutput } from '../../cli/dvc/contract'
28+
import { ExperimentsOutput, PlotsOutputOrError } from '../../cli/dvc/contract'
2929
import { Experiments } from '../../experiments'
3030
import { getColorScale, truncateVerticalTitle } from '../vega/util'
3131
import { definedAndNonEmpty, reorderObjectList } from '../../util/array'
@@ -39,6 +39,7 @@ import {
3939
MultiSourceEncoding,
4040
MultiSourceVariations
4141
} from '../multiSource/collect'
42+
import { isDvcError } from '../../cli/dvc/reader'
4243

4344
export class PlotsModel extends ModelWithPersistence {
4445
private readonly experiments: Experiments
@@ -104,7 +105,11 @@ export class PlotsModel extends ModelWithPersistence {
104105
return this.removeStaleData()
105106
}
106107

107-
public async transformAndSetPlots(data: PlotsOutput, revs: string[]) {
108+
public async transformAndSetPlots(data: PlotsOutputOrError, revs: string[]) {
109+
if (isDvcError(data)) {
110+
return
111+
}
112+
108113
const cliIdToLabel = this.getCLIIdToLabel()
109114

110115
this.fetchedRevs = new Set([

extension/src/plots/paths/model.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,16 @@ describe('PathsModel', () => {
257257
const noChildren = model.getChildren(logsLoss)
258258
expect(noChildren).toStrictEqual([])
259259
})
260+
261+
it('should not provide error as a path when the CLI throws an error', () => {
262+
const model = new PathsModel(mockDvcRoot, buildMockMemento())
263+
model.transformAndSet({
264+
error: {
265+
msg: 'UNEXPECTED ERROR: a strange thing happened',
266+
type: 'Caught Error'
267+
}
268+
})
269+
270+
expect(model.getTerminalNodes()).toStrictEqual([])
271+
})
260272
})

extension/src/plots/paths/model.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import {
66
PlotPath,
77
TemplateOrder
88
} from './collect'
9-
import { PlotsOutput } from '../../cli/dvc/contract'
109
import { PathSelectionModel } from '../../path/selection/model'
1110
import { PersistenceKey } from '../../persistence/constants'
1211
import { performSimpleOrderedUpdate } from '../../util/array'
1312
import { MultiSourceEncoding } from '../multiSource/collect'
13+
import { isDvcError } from '../../cli/dvc/reader'
14+
import { PlotsOutputOrError } from '../../cli/dvc/contract'
1415

1516
export class PathsModel extends PathSelectionModel<PlotPath> {
1617
private templateOrder: TemplateOrder
@@ -26,7 +27,11 @@ export class PathsModel extends PathSelectionModel<PlotPath> {
2627
)
2728
}
2829

29-
public transformAndSet(data: PlotsOutput) {
30+
public transformAndSet(data: PlotsOutputOrError) {
31+
if (isDvcError(data)) {
32+
return
33+
}
34+
3035
const paths = collectPaths(this.data, data)
3136

3237
this.setNewStatuses(paths)

0 commit comments

Comments
 (0)