From 457f3fc9f8f824abd1adc0baa1cf100d547194c2 Mon Sep 17 00:00:00 2001 From: Nika Salamadze <33500361+nsalamad@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:28:22 -0500 Subject: [PATCH] fix: fix project showing up as undefined (#248) --- src/cli/OrganizationsCLIController.ts | 12 ++++----- src/cli/UsagesCLIController.ts | 38 ++++++++++++++++----------- src/cli/utils/execShell.ts | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/cli/OrganizationsCLIController.ts b/src/cli/OrganizationsCLIController.ts index 33868e1d..e20d7a19 100644 --- a/src/cli/OrganizationsCLIController.ts +++ b/src/cli/OrganizationsCLIController.ts @@ -29,7 +29,12 @@ export class OrganizationsCLIController extends BaseCLIController { } const { code, error, output } = await this.execDvc('organizations get') - if (code === 0) { + if (code !== 0) { + vscode.window.showErrorMessage( + `Retrieving organizations failed: ${error?.message}}`, + ) + return {} + } else { const organizations = JSON.parse(output) as Organization[] const orgsMap = organizations.reduce((result, currentOrg) => { result[currentOrg.id] = currentOrg @@ -38,11 +43,6 @@ export class OrganizationsCLIController extends BaseCLIController { StateManager.setWorkspaceState(KEYS.ORGANIZATIONS, orgsMap) return orgsMap - } else { - vscode.window.showErrorMessage( - `Retrieving organizations failed: ${error?.message}}`, - ) - return {} } } diff --git a/src/cli/UsagesCLIController.ts b/src/cli/UsagesCLIController.ts index b514544e..6445b25e 100644 --- a/src/cli/UsagesCLIController.ts +++ b/src/cli/UsagesCLIController.ts @@ -1,6 +1,7 @@ import { StateManager, KEYS } from '../StateManager' import { showBusyMessage, hideBusyMessage } from '../components/statusBarItem' import { BaseCLIController } from './BaseCLIController' +import * as vscode from 'vscode' export type JSONMatch = { key: string @@ -41,26 +42,33 @@ export class UsagesCLIController extends BaseCLIController { public async usages(savedFilePath?: string): Promise { showBusyMessage('Finding Devcycle code usages') - const { output } = await this.execDvc( + const { code, error, output } = await this.execDvc( `usages --format=json${ savedFilePath ? ` --include=${savedFilePath}` : '' }`, ) - - const matches = JSON.parse(output) as JSONMatch[] hideBusyMessage() - const codeUsageKeys = matches.reduce( - (map, match) => { - map[match.key] = true - return map - }, - {} as Record, - ) - StateManager.setFolderState( - this.folder.name, - KEYS.CODE_USAGE_KEYS, - codeUsageKeys, - ) + + if (code !== 0) { + vscode.window.showErrorMessage( + `Error finding code usages: ${error?.message}}`, + ) + return [] + } else { + const matches = JSON.parse(output) as JSONMatch[] + const codeUsageKeys = matches.reduce( + (map, match) => { + map[match.key] = true + return map + }, + {} as Record, + ) + StateManager.setFolderState( + this.folder.name, + KEYS.CODE_USAGE_KEYS, + codeUsageKeys, + ) return matches + } } } diff --git a/src/cli/utils/execShell.ts b/src/cli/utils/execShell.ts index 8eafbda3..f1e59712 100644 --- a/src/cli/utils/execShell.ts +++ b/src/cli/utils/execShell.ts @@ -16,7 +16,7 @@ export function execShell(cmd: string, cwd: string) { resolve({ output: out, error: err, - code: err.code || 0, + code: err.code || 1, // If no error code is provided, return 1 as default code to indicate error }) } resolve({