Skip to content

Commit 803a5d4

Browse files
authored
Ensure that accessing the config doesn't throw error (#3831)
1 parent 16a9737 commit 803a5d4

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

extension/src/setup/index.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ import { createFileSystemWatcher } from '../fileSystem/watcher'
4343
import { EventName } from '../telemetry/constants'
4444
import { WorkspaceScale } from '../telemetry/collect'
4545
import { gitPath } from '../cli/git/constants'
46-
import { Flag, ConfigKey as DvcConfigKey, DOT_DVC } from '../cli/dvc/constants'
46+
import {
47+
Flag,
48+
ConfigKey as DvcConfigKey,
49+
DOT_DVC,
50+
Args
51+
} from '../cli/dvc/constants'
4752
import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
4853
import {
4954
ConfigKey as ExtensionConfigKey,
@@ -297,8 +302,7 @@ export class Setup
297302
if (!cwd) {
298303
return
299304
}
300-
return this.internalCommands.executeCommand(
301-
AvailableCommands.CONFIG,
305+
return await this.accessConfig(
302306
cwd,
303307
Flag.GLOBAL,
304308
Flag.UNSET,
@@ -308,24 +312,19 @@ export class Setup
308312

309313
const cwd = this.dvcRoots[0]
310314

311-
try {
312-
await this.internalCommands.executeCommand(
313-
AvailableCommands.CONFIG,
314-
cwd,
315-
Flag.LOCAL,
316-
Flag.UNSET,
317-
DvcConfigKey.STUDIO_TOKEN
318-
)
319-
} catch {}
320-
try {
321-
return await this.internalCommands.executeCommand(
322-
AvailableCommands.CONFIG,
323-
cwd,
324-
Flag.GLOBAL,
325-
Flag.UNSET,
326-
DvcConfigKey.STUDIO_TOKEN
327-
)
328-
} catch {}
315+
await this.accessConfig(
316+
cwd,
317+
Flag.LOCAL,
318+
Flag.UNSET,
319+
DvcConfigKey.STUDIO_TOKEN
320+
)
321+
322+
return await this.accessConfig(
323+
cwd,
324+
Flag.GLOBAL,
325+
Flag.UNSET,
326+
DvcConfigKey.STUDIO_TOKEN
327+
)
329328
}
330329

331330
public async saveStudioAccessToken() {
@@ -344,13 +343,7 @@ export class Setup
344343
return
345344
}
346345

347-
await this.internalCommands.executeCommand(
348-
AvailableCommands.CONFIG,
349-
cwd,
350-
Flag.GLOBAL,
351-
DvcConfigKey.STUDIO_TOKEN,
352-
token
353-
)
346+
await this.accessConfig(cwd, Flag.GLOBAL, DvcConfigKey.STUDIO_TOKEN, token)
354347
return this.updateIsStudioConnected()
355348
}
356349

@@ -706,18 +699,25 @@ export class Setup
706699
this.studioAccessToken = undefined
707700
return
708701
}
709-
this.studioAccessToken = await this.internalCommands.executeCommand(
710-
AvailableCommands.CONFIG,
702+
this.studioAccessToken = await this.accessConfig(
711703
cwd,
712704
DvcConfigKey.STUDIO_TOKEN
713705
)
714-
return
715706
}
716707

717-
this.studioAccessToken = await this.internalCommands.executeCommand(
718-
AvailableCommands.CONFIG,
708+
this.studioAccessToken = await this.accessConfig(
719709
this.dvcRoots[0],
720710
DvcConfigKey.STUDIO_TOKEN
721711
)
722712
}
713+
714+
private async accessConfig(cwd: string, ...args: Args) {
715+
try {
716+
return await this.internalCommands.executeCommand(
717+
AvailableCommands.CONFIG,
718+
cwd,
719+
...args
720+
)
721+
} catch {}
722+
}
723723
}

0 commit comments

Comments
 (0)