Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions extension/src/cli/dvc/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,13 @@ export type PlotError = {
source?: string
} & ErrorContents

export interface PlotsOutput {
data: { [path: string]: Plot[] }
export type RawPlotsOutput = {
data?: { [path: string]: Plot[] }
errors?: PlotError[]
}

export type PlotsOutput = RawPlotsOutput & {
data: { [path: string]: Plot[] }
}

export type PlotsOutputOrError = PlotsOutput | DvcError
25 changes: 24 additions & 1 deletion extension/src/cli/dvc/reader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,30 @@ describe('CliReader', () => {
mockedCreateProcess.mockReturnValueOnce(getMockedProcess(''))

const plots = await dvcReader.plotsDiff(cwd, 'HEAD')
expect(plots).toStrictEqual({})
expect(plots).toStrictEqual({ data: {} })
})

it('should remove an empty errors array from the output', async () => {
const cwd = __dirname

mockedCreateProcess.mockReturnValueOnce(
getMockedProcess(JSON.stringify({ errors: [] }))
)

const plots = await dvcReader.plotsDiff(cwd, 'main')
expect(plots).toStrictEqual({ data: {} })
})

it('should not remove an errors array with entries from the output', async () => {
const cwd = __dirname
const errors = [{ msg: 'something went wrong' }]

mockedCreateProcess.mockReturnValueOnce(
getMockedProcess(JSON.stringify({ errors }))
)

const plots = await dvcReader.plotsDiff(cwd, 'main')
expect(plots).toStrictEqual({ data: {}, errors })
})

it('should match the expected output', async () => {
Expand Down
28 changes: 22 additions & 6 deletions extension/src/cli/dvc/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ import {
ExperimentsOutput,
EXPERIMENT_WORKSPACE_ID,
PlotsOutput,
PlotsOutputOrError
PlotsOutputOrError,
RawPlotsOutput
} from './contract'
import { getOptions } from './options'
import { typeCheckCommands } from '..'
import { MaybeConsoleError } from '../error'
import { Logger } from '../../common/logger'
import { parseNonStandardJson } from '../../util/json'
import { definedAndNonEmpty } from '../../util/array'

const defaultExperimentsOutput: ExperimentsOutput = {
[EXPERIMENT_WORKSPACE_ID]: { baseline: {} }
}

export const isDvcError = <
T extends ExperimentsOutput | DataStatusOutput | PlotsOutput
T extends ExperimentsOutput | DataStatusOutput | RawPlotsOutput
>(
dataOrError: T | DvcError
): dataOrError is DvcError =>
Expand Down Expand Up @@ -83,11 +85,11 @@ export class DvcReader extends DvcCli {
return output
}

public plotsDiff(
public async plotsDiff(
cwd: string,
...revisions: string[]
): Promise<PlotsOutputOrError> {
return this.readProcessJson<PlotsOutput>(
const output = await this.readProcessJson<RawPlotsOutput>(
cwd,
Command.PLOTS,
SubCommand.DIFF,
Expand All @@ -96,6 +98,20 @@ export class DvcReader extends DvcCli {
TEMP_PLOTS_DIR,
Flag.SPLIT
)
if (isDvcError(output)) {
return output
}

const { data, errors } = output
const expectedOutput: PlotsOutput = {
data: data || {}
}

if (definedAndNonEmpty(errors)) {
expectedOutput.errors = errors
}

return expectedOutput
}

public async root(cwd: string): Promise<string | undefined> {
Expand Down Expand Up @@ -125,7 +141,7 @@ export class DvcReader extends DvcCli {
} catch {}
}

private readProcessJson<T extends DataStatusOutput | PlotsOutput>(
private readProcessJson<T extends DataStatusOutput | RawPlotsOutput>(
cwd: string,
command: Command,
...args: Args
Expand All @@ -134,7 +150,7 @@ export class DvcReader extends DvcCli {
}

private async readProcess<
T extends DataStatusOutput | ExperimentsOutput | PlotsOutput
T extends DataStatusOutput | ExperimentsOutput | RawPlotsOutput
>(cwd: string, defaultValue: string, ...args: Args): Promise<T | DvcError> {
try {
const output =
Expand Down