diff --git a/src/commands/env/var/set.ts b/src/commands/env/var/set.ts index 5b4a7d1f..6e32f08d 100644 --- a/src/commands/env/var/set.ts +++ b/src/commands/env/var/set.ts @@ -52,55 +52,6 @@ export default class ConfigSet extends Command { }, {}); } - parseErrors(errorObject: any, targetCompute: string) { - // may have create a cleaner way to parse the errors - // to fit the sfdx json error object, but this currently works - - const errObj = errorObject.stack; - const isInvalidEnvironment = errObj.includes("Error: Couldn't"); - const hasNoInput = errObj.includes('Error: Usage:'); - const isInvalidInput = !hasNoInput; - - if (isInvalidEnvironment) { - const errorStackStartIndex = errObj.indexOf('at'); - const errStack = errObj.substr(errorStackStartIndex); - errorObject.message = `Couldn't find that app <${targetCompute}>`; - errorObject.stack = errStack; - this.error(errObj); - } - - if (isInvalidInput) { - const errorIndex = errObj.indexOf(':') + 1; - const keyValueIndex = errObj.indexOf('value') + 5; - - // eslint-disable-next-line no-control-regex - const errMessage = errObj - .substr(errorIndex, keyValueIndex) - // eslint-disable-next-line no-control-regex - .replace(/\u001b\[.*?m/g, '') - .replace('\n', '') - .replace(' ', ''); - // eslint-disable-next-line no-control-regex - const errStack = errObj - .substr(keyValueIndex) - // eslint-disable-next-line no-control-regex - .replace(/\u001b\[.*?m\r?\n|\r/g, '') - .replace(' ', ''); - - errorObject.message = errMessage; - errorObject.stack = errStack; - this.error(errObj); - } - - if (hasNoInput) { - const errorStackStartIndex = errObj.indexOf('at'); - const errStack = errObj.substr(errorStackStartIndex); - errorObject.message = 'Must specify KEY and VALUE to set.'; - errorObject.stack = errStack; - this.error(errObj); - } - } - async run() { const { flags, argv } = await this.parse(ConfigSet); this.postParseHook(flags); @@ -122,32 +73,28 @@ export default class ConfigSet extends Command { const appName = await resolveAppNameForEnvironment(targetCompute); - if (flags.json) { - try { - const configPairs = this.parseKeyValuePairs(argv); + const configPairs = this.parseKeyValuePairs(argv); - await this.client.patch(`/apps/${appName}/config-vars`, { - data: configPairs, - }); - - return []; - } catch (err: any) { - this.parseErrors(err, targetCompute); - } - } else { - const configPairs = this.parseKeyValuePairs(argv); - - cli.action.start( - `Setting ${Object.keys(configPairs) - .map((key) => herokuColor.configVar(key)) - .join(', ')} and restarting ${herokuColor.app(targetCompute)}` - ); + cli.action.start( + `Setting ${Object.keys(configPairs) + .map((key) => herokuColor.configVar(key)) + .join(', ')} and restarting ${herokuColor.app(targetCompute)}` + ); + try { await this.client.patch(`/apps/${appName}/config-vars`, { data: configPairs, }); cli.action.stop(); + + return []; + } catch (error: any) { + cli.action.stop('failed'); + if (error.data?.message?.includes("Couldn't find that app")) { + this.error(new Error(`Could not find environment <${appName}>`)); + } + this.error(error); } } } diff --git a/test/commands/env/var/unset.test.ts b/test/commands/env/var/unset.test.ts index 968a9fa1..082bd12f 100644 --- a/test/commands/env/var/unset.test.ts +++ b/test/commands/env/var/unset.test.ts @@ -24,6 +24,9 @@ describe('sf env:var:unset', () => { test .stdout() .stderr() + // Adding retries here because there is some kind of race condition that causes fancy-test to not + // fully capture the value of stderr when running in CI (╯°□°)╯︵ ┻━┻ + .retries(2) .nock('https://api.heroku.com', (api) => api .patch('/apps/my-environment/config-vars', {