From b5678914f24edd9df2e942a85eb4551b86b6e132 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 15:15:49 +0000 Subject: [PATCH 1/4] Bump typescript from 4.3.5 to 4.4.3 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.3.5 to 4.4.3. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v4.3.5...v4.4.3) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e50cd1314a..ec87377135 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,6 @@ "prettier": "2.4.1", "rimraf": "3.0.2", "ts-jest": "26.5.6", - "typescript": "4.3.5" + "typescript": "4.4.3" } } diff --git a/yarn.lock b/yarn.lock index d50402c2fe..b3d36d61e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4571,10 +4571,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@4.4.3: + version "4.4.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.3.tgz#bdc5407caa2b109efd4f82fe130656f977a29324" + integrity sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA== union-value@^1.0.0: version "1.0.1" From aeee72d4dd8e838ca729689ef7f41a32fb16d354 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Sun, 3 Oct 2021 16:27:46 -0300 Subject: [PATCH 2/4] (fix): extract error message --- src/git.ts | 10 +++++++--- src/lib.ts | 3 ++- src/ssh.ts | 4 ++-- src/util.ts | 7 +++++++ src/worktree.ts | 4 ++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/git.ts b/src/git.ts index 4d733aa47c..c91d3c2964 100644 --- a/src/git.ts +++ b/src/git.ts @@ -4,7 +4,11 @@ import fs from 'fs' import {ActionInterface, Status, TestFlag} from './constants' import {execute} from './execute' import {generateWorktree} from './worktree' -import {isNullOrUndefined, suppressSensitiveInformation} from './util' +import { + extractErrorMessage, + isNullOrUndefined, + suppressSensitiveInformation +} from './util' /* Initializes git in the workspace. */ export async function init(action: ActionInterface): Promise { @@ -63,7 +67,7 @@ export async function init(action: ActionInterface): Promise { } catch (error) { throw new Error( `There was an error initializing the repository: ${suppressSensitiveInformation( - error.message, + extractErrorMessage(error), action )} ❌` ) @@ -208,7 +212,7 @@ export async function deploy(action: ActionInterface): Promise { } catch (error) { throw new Error( `The deploy step encountered an error: ${suppressSensitiveInformation( - error.message, + extractErrorMessage(error), action )} ❌` ) diff --git a/src/lib.ts b/src/lib.ts index 94738cf8b4..5703e7c0c7 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -4,6 +4,7 @@ import {deploy, init} from './git' import {configureSSH} from './ssh' import { checkParameters, + extractErrorMessage, generateFolderPath, generateRepositoryPath, generateTokenType @@ -52,7 +53,7 @@ export default async function run( status = await deploy(settings) } catch (error) { status = Status.FAILED - setFailed(error.message) + setFailed(extractErrorMessage(error)) } finally { info( `${ diff --git a/src/ssh.ts b/src/ssh.ts index 7df9e3a3d8..1c90392018 100644 --- a/src/ssh.ts +++ b/src/ssh.ts @@ -3,7 +3,7 @@ import {mkdirP} from '@actions/io' import {execFileSync, execSync} from 'child_process' import {appendFileSync} from 'fs' import {ActionInterface} from './constants' -import {suppressSensitiveInformation} from './util' +import {extractErrorMessage, suppressSensitiveInformation} from './util' export async function configureSSH(action: ActionInterface): Promise { try { @@ -46,7 +46,7 @@ export async function configureSSH(action: ActionInterface): Promise { } catch (error) { throw new Error( `The ssh client configuration encountered an error: ${suppressSensitiveInformation( - error.message, + extractErrorMessage(error), action )} ❌` ) diff --git a/src/util.ts b/src/util.ts index 7f67b14983..dba4a4193e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -90,6 +90,13 @@ export const suppressSensitiveInformation = ( return value } +export const extractErrorMessage = (error: unknown): string => + error instanceof Error + ? error.message + : typeof error == 'string' + ? error + : JSON.stringify(error) + /** Strips the protocol from a provided URL. */ export const stripProtocolFromUrl = (url: string): string => url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0] diff --git a/src/worktree.ts b/src/worktree.ts index e6cde73e6c..9ef4722211 100644 --- a/src/worktree.ts +++ b/src/worktree.ts @@ -1,7 +1,7 @@ import {info} from '@actions/core' import {ActionInterface} from './constants' import {execute} from './execute' -import {suppressSensitiveInformation} from './util' +import {extractErrorMessage, suppressSensitiveInformation} from './util' export class GitCheckout { orphan = false @@ -77,7 +77,7 @@ export async function generateWorktree( } catch (error) { throw new Error( `There was an error creating the worktree: ${suppressSensitiveInformation( - error.message, + extractErrorMessage(error), action )} ❌` ) From 9caf0a9cc78f8a9d067d73c322ad2c9f0fc390b0 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Tue, 5 Oct 2021 07:54:33 -0300 Subject: [PATCH 3/4] (fix): error is unknown on __tests__ --- __tests__/git.test.ts | 4 ++-- __tests__/ssh.test.ts | 2 +- __tests__/util.test.ts | 10 +++++----- __tests__/worktree.error.test.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 44da5e4dca..69e9bfac55 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -80,7 +80,7 @@ describe('git', () => { try { await init(action) } catch (error) { - expect(error.message).toBe( + expect(error instanceof Error && error.message).toBe( 'There was an error initializing the repository: Mocked throw ❌' ) } @@ -419,7 +419,7 @@ describe('git', () => { try { await deploy(action) } catch (error) { - expect(error.message).toBe( + expect(error instanceof Error && error.message).toBe( 'The deploy step encountered an error: Mocked throw ❌' ) } diff --git a/__tests__/ssh.test.ts b/__tests__/ssh.test.ts index b9dc73cde6..394815063b 100644 --- a/__tests__/ssh.test.ts +++ b/__tests__/ssh.test.ts @@ -133,7 +133,7 @@ describe('configureSSH', () => { try { await configureSSH(action) } catch (error) { - expect(error.message).toBe( + expect(error instanceof Error && error.message).toBe( 'The ssh client configuration encountered an error: Mocked throw ❌' ) } diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index a7ade4a396..e23e515d41 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -222,7 +222,7 @@ describe('util', () => { try { checkParameters(action) } catch (e) { - expect(e.message).toMatch( + expect(e instanceof Error && e.message).toMatch( 'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.' ) } @@ -242,7 +242,7 @@ describe('util', () => { try { checkParameters(action) } catch (e) { - expect(e.message).toMatch( + expect(e instanceof Error && e.message).toMatch( 'No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.' ) } @@ -262,7 +262,7 @@ describe('util', () => { try { checkParameters(action) } catch (e) { - expect(e.message).toMatch('Branch is required.') + expect(e instanceof Error && e.message).toMatch('Branch is required.') } }) @@ -280,7 +280,7 @@ describe('util', () => { try { checkParameters(action) } catch (e) { - expect(e.message).toMatch( + expect(e instanceof Error && e.message).toMatch( 'You must provide the action with a folder to deploy.' ) } @@ -301,7 +301,7 @@ describe('util', () => { action.folderPath = generateFolderPath(action) checkParameters(action) } catch (e) { - expect(e.message).toMatch( + expect(e instanceof Error && e.message).toMatch( `The directory you're trying to deploy named notARealFolder doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗` ) } diff --git a/__tests__/worktree.error.test.ts b/__tests__/worktree.error.test.ts index 0bbf7df6fd..73f91410f1 100644 --- a/__tests__/worktree.error.test.ts +++ b/__tests__/worktree.error.test.ts @@ -28,7 +28,7 @@ describe('generateWorktree', () => { true ) } catch (error) { - expect(error.message).toBe( + expect(error instanceof Error && error.message).toBe( 'There was an error creating the worktree: Mocked throw ❌' ) } From 412ce8118384803f3436940d6ea82578f587301e Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Wed, 6 Oct 2021 09:00:21 -0300 Subject: [PATCH 4/4] (fix): add cover --- __tests__/util.test.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index e23e515d41..fa5e1c6ab4 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -6,7 +6,8 @@ import { generateFolderPath, suppressSensitiveInformation, checkParameters, - stripProtocolFromUrl + stripProtocolFromUrl, + extractErrorMessage } from '../src/util' describe('util', () => { @@ -327,4 +328,22 @@ describe('util', () => { ) }) }) + + describe('extractErrorMessage', () => { + it('gets the message of a Error', () => { + expect(extractErrorMessage(new Error('a error message'))).toBe( + 'a error message' + ) + }) + + it('gets the message of a string', () => { + expect(extractErrorMessage('a error message')).toBe('a error message') + }) + + it('gets the message of a object', () => { + expect(extractErrorMessage({special: 'a error message'})).toBe( + `{"special":"a error message"}` + ) + }) + }) })