From ed639e43360aceb9fb10579b4fc98463cbff5175 Mon Sep 17 00:00:00 2001 From: yaroslav-codefresh Date: Fri, 29 Mar 2019 11:04:43 +0200 Subject: [PATCH] print workflow id + helper renamed --- .../commands/helm/chart/helm-charts.sdk.spec.js | 2 +- .../cli/commands/helm/chart/install-chart.cmd.js | 2 +- .../cli/commands/helm/chart/promote-chart.cmd.js | 2 +- .../commands/helm/release/delete-release.cmd.js | 2 +- .../helm/release/helm-releases.sdk.spec.js | 2 +- .../commands/helm/release/test-release.cmd.js | 2 +- lib/interface/cli/commands/pipeline/run.cf.js | 2 +- lib/interface/cli/commands/pipeline/run.local.js | 2 +- .../cli/commands/workflow/restart.cmd.js | 2 +- .../cli/commands/workflow/workflow.sdk.spec.js | 2 +- lib/interface/cli/helpers/helpers.sdk.spec.js | 4 ++-- .../cli/helpers/{workflow.js => logs.js} | 16 +++++++++++++--- package.json | 2 +- 13 files changed, 26 insertions(+), 16 deletions(-) rename lib/interface/cli/helpers/{workflow.js => logs.js} (82%) diff --git a/lib/interface/cli/commands/helm/chart/helm-charts.sdk.spec.js b/lib/interface/cli/commands/helm/chart/helm-charts.sdk.spec.js index 22b5dcebb..c5e89d595 100644 --- a/lib/interface/cli/commands/helm/chart/helm-charts.sdk.spec.js +++ b/lib/interface/cli/commands/helm/chart/helm-charts.sdk.spec.js @@ -8,7 +8,7 @@ installCmd = installCmd.toCommand(); promoteCmd = promoteCmd.toCommand(); jest.mock('../../../helpers/helm'); -jest.mock('../../../helpers/workflow'); +jest.mock('../../../helpers/logs'); jest.spyOn(process, 'exit').mockImplementation(); const request = require('requestretry'); diff --git a/lib/interface/cli/commands/helm/chart/install-chart.cmd.js b/lib/interface/cli/commands/helm/chart/install-chart.cmd.js index 7c64d6c3b..e7886781f 100644 --- a/lib/interface/cli/commands/helm/chart/install-chart.cmd.js +++ b/lib/interface/cli/commands/helm/chart/install-chart.cmd.js @@ -1,5 +1,5 @@ const Command = require('../../../Command'); -const { followLogs } = require('../../../helpers/workflow'); +const { followLogs } = require('../../../helpers/logs'); const { sdk } = require('../../../../../logic'); const { normalizeValues, normalizeSetValues } = require('../../../helpers/helm'); const Output = require('../../../../../output/Output'); diff --git a/lib/interface/cli/commands/helm/chart/promote-chart.cmd.js b/lib/interface/cli/commands/helm/chart/promote-chart.cmd.js index 4e9565ec8..11fbd462e 100644 --- a/lib/interface/cli/commands/helm/chart/promote-chart.cmd.js +++ b/lib/interface/cli/commands/helm/chart/promote-chart.cmd.js @@ -1,5 +1,5 @@ const Command = require('../../../Command'); -const { followLogs } = require('../../../helpers/workflow'); +const { followLogs } = require('../../../helpers/logs'); const { sdk } = require('../../../../../logic'); const { normalizeValues, normalizeSetValues } = require('../../../helpers/helm'); const Output = require('../../../../../output/Output'); diff --git a/lib/interface/cli/commands/helm/release/delete-release.cmd.js b/lib/interface/cli/commands/helm/release/delete-release.cmd.js index 006cb43ac..98eaa8ba6 100644 --- a/lib/interface/cli/commands/helm/release/delete-release.cmd.js +++ b/lib/interface/cli/commands/helm/release/delete-release.cmd.js @@ -1,6 +1,6 @@ const Command = require('../../../Command'); const { sdk } = require('../../../../../logic'); -const { followLogs } = require('../../../helpers/workflow'); +const { followLogs } = require('../../../helpers/logs'); const Output = require('../../../../../output/Output'); const install = new Command({ diff --git a/lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js b/lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js index 1b290f07e..78b6a29b6 100644 --- a/lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js +++ b/lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js @@ -8,7 +8,7 @@ deleteCmd = deleteCmd.toCommand(); testCmd = testCmd.toCommand(); jest.mock('../../../helpers/helm'); -jest.mock('../../../helpers/workflow'); +jest.mock('../../../helpers/logs'); jest.spyOn(process, 'exit').mockImplementation(); const request = require('requestretry'); diff --git a/lib/interface/cli/commands/helm/release/test-release.cmd.js b/lib/interface/cli/commands/helm/release/test-release.cmd.js index 7f14b92c2..9dcdb5942 100644 --- a/lib/interface/cli/commands/helm/release/test-release.cmd.js +++ b/lib/interface/cli/commands/helm/release/test-release.cmd.js @@ -1,5 +1,5 @@ const Command = require('../../../Command'); -const { followLogs } = require('../../../helpers/workflow'); +const { followLogs } = require('../../../helpers/logs'); const { sdk } = require('../../../../../logic'); const Output = require('../../../../../output/Output'); diff --git a/lib/interface/cli/commands/pipeline/run.cf.js b/lib/interface/cli/commands/pipeline/run.cf.js index faf30d43d..69eaf3bc1 100644 --- a/lib/interface/cli/commands/pipeline/run.cf.js +++ b/lib/interface/cli/commands/pipeline/run.cf.js @@ -1,6 +1,6 @@ const RunBaseCommand = require('./run.base'); const { sdk } = require('../../../../logic'); -const { followLogs } = require('../../helpers/workflow'); +const { followLogs } = require('../../helpers/logs'); function _buildBody(data) { const body = { diff --git a/lib/interface/cli/commands/pipeline/run.local.js b/lib/interface/cli/commands/pipeline/run.local.js index feed3add2..0531e97fd 100644 --- a/lib/interface/cli/commands/pipeline/run.local.js +++ b/lib/interface/cli/commands/pipeline/run.local.js @@ -5,7 +5,7 @@ const path = require('path'); const DEFAULTS = require('../../defaults'); const _ = require('lodash'); const { sdk } = require('../../../../logic'); -const { followLogs } = require('../../helpers/workflow'); +const { followLogs } = require('../../helpers/logs'); const chalk = require('chalk'); const regex = /##[0-9a-f]{24}##/i; diff --git a/lib/interface/cli/commands/workflow/restart.cmd.js b/lib/interface/cli/commands/workflow/restart.cmd.js index a924b11ab..e9e691f09 100644 --- a/lib/interface/cli/commands/workflow/restart.cmd.js +++ b/lib/interface/cli/commands/workflow/restart.cmd.js @@ -1,5 +1,5 @@ const Command = require('../../Command'); -const { followLogs } = require('../../helpers/workflow'); +const { followLogs } = require('../../helpers/logs'); const { sdk } = require('../../../../logic'); const restart = new Command({ diff --git a/lib/interface/cli/commands/workflow/workflow.sdk.spec.js b/lib/interface/cli/commands/workflow/workflow.sdk.spec.js index cc73c4379..6bbcae746 100644 --- a/lib/interface/cli/commands/workflow/workflow.sdk.spec.js +++ b/lib/interface/cli/commands/workflow/workflow.sdk.spec.js @@ -21,7 +21,7 @@ jest.mock('../../../../logic/entities/Workflow', () => { fromResponse: res => res, }; }); -jest.mock('../../helpers/workflow'); +jest.mock('../../helpers/logs'); const request = require('requestretry'); diff --git a/lib/interface/cli/helpers/helpers.sdk.spec.js b/lib/interface/cli/helpers/helpers.sdk.spec.js index 3d3fe099c..3b2ee89f8 100644 --- a/lib/interface/cli/helpers/helpers.sdk.spec.js +++ b/lib/interface/cli/helpers/helpers.sdk.spec.js @@ -6,7 +6,7 @@ const { Config } = require('codefresh-sdk'); const { normalizeValues } = require('./helm'); const { validatePipelineSpec, validatePipelineYaml } = require('./validation'); -const { followLogs } = require('./workflow'); +const { followLogs } = require('./logs'); const { printTableForAuthContexts } = require('./auth'); const { sdk } = require('../../../logic'); @@ -56,7 +56,7 @@ describe('helpers using sdk', () => { }); }); - describe('workflow', () => { + describe('logs', () => { it('should handle showing logs', async () => { const workflowId = 'id'; jest.spyOn(process, 'exit').mockImplementation(); diff --git a/lib/interface/cli/helpers/workflow.js b/lib/interface/cli/helpers/logs.js similarity index 82% rename from lib/interface/cli/helpers/workflow.js rename to lib/interface/cli/helpers/logs.js index 2f8cf43cb..a68b95e63 100644 --- a/lib/interface/cli/helpers/workflow.js +++ b/lib/interface/cli/helpers/logs.js @@ -1,9 +1,11 @@ const Promise = require('bluebird'); const _ = require('lodash'); const request = require('requestretry'); +const CFError = require('cf-errors'); const { sdk } = require('../../../logic'); const Workflow = require('../../../logic/entities/Workflow'); +const Output = require('../../../output/Output'); const END_STATUSES = ['error', 'success', 'terminated']; @@ -15,7 +17,10 @@ async function _fallbackLogs(workflowId, interval, retriesLeft) { await sdk.logs.showWorkflowLogs(workflowId, true); return; } catch (e) { - console.log(`Could not retrieve logs due to error: ${e.message}`); + Output.printError(new CFError({ + message: `Could not retrieve logs for workflow: ${workflowId}`, + cause: e, + })); } let failedToGetStatus = false; @@ -51,10 +56,15 @@ const followLogs = async (workflowId) => { try { await sdk.logs.showWorkflowLogs(workflowId, true); } catch (e) { + const error = new CFError({ + message: `Could not retrieve logs for workflow: ${workflowId}`, + cause: e, + }); if (!process.env.CF_CLI_RUN_WAIT_FALLBACK) { - throw e; + throw error; + } else { + Output.printError(error); } - console.log(`Could not retrieve logs due to error: ${e.message}`); await _fallbackLogs(workflowId, config.logs.fallback.interval, config.logs.fallback.maxAttempts); } const json = await sdk.workflows.get({ id: workflowId }); diff --git a/package.json b/package.json index 883a4826e..91b631a11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.17.10", + "version": "0.17.11", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,