From 8c8386ddc356f279f3f7b3c503b403bf9f3b912a Mon Sep 17 00:00:00 2001 From: Timothy Jones Date: Tue, 25 Oct 2022 20:17:12 +1100 Subject: [PATCH] fix: Add error messages to the ignored option debug logs --- src/verifier/argumentMapper/arguments.ts | 55 +++++++++++++++++++----- src/verifier/argumentMapper/index.ts | 8 ++-- src/verifier/argumentMapper/types.ts | 20 +++++++-- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/verifier/argumentMapper/arguments.ts b/src/verifier/argumentMapper/arguments.ts index a93d6aec..48211ae7 100644 --- a/src/verifier/argumentMapper/arguments.ts +++ b/src/verifier/argumentMapper/arguments.ts @@ -77,13 +77,16 @@ export const ffiFnMapping: FnMapping< } } if (messages.length > 0) { - return { status: FnValidationStatus.FAIL }; + return { status: FnValidationStatus.FAIL, messages }; } return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: ['No customProviderHeaders option provided'], + }; }, }, pactffiVerifierAddDirectorySource: { @@ -141,7 +144,10 @@ export const ffiFnMapping: FnMapping< return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: ['No pactUrls option provided'], + }; }, }, pactffiVerifierBrokerSourceWithSelectors: { @@ -166,7 +172,12 @@ export const ffiFnMapping: FnMapping< ); return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: [ + 'No pactBrokerUrl option / PACT_BROKER_BASE_URL set, or no provider option set', + ], + }; }, }, pactffiVerifierSetConsumerFilters: { @@ -175,7 +186,12 @@ export const ffiFnMapping: FnMapping< ffi.pactffiVerifierSetConsumerFilters(handle, options.consumerFilters); return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: [ + 'Either no consumerFilters option provided, or the array was empty', + ], + }; }, }, pactffiVerifierSetFailIfNoPactsFound: { @@ -187,7 +203,10 @@ export const ffiFnMapping: FnMapping< ); return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: ['No failIfNoPactsFound option provided'], + }; }, }, pactffiVerifierSetFilterInfo: { @@ -211,7 +230,12 @@ export const ffiFnMapping: FnMapping< return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: [ + 'None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment', + ], + }; }, }, pactffiVerifierSetProviderInfo: { @@ -242,7 +266,10 @@ export const ffiFnMapping: FnMapping< return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: ['No failIfNoPactsFound option provided'], + }; }, }, pactffiVerifierSetPublishOptions: { @@ -261,7 +288,12 @@ export const ffiFnMapping: FnMapping< ); return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: [ + 'No publishVerificationResult option / PACT_BROKER_PUBLISH_VERIFICATION_RESULTS set, or no providerVersion option', + ], + }; }, }, pactffiVerifierSetVerificationOptions: { @@ -275,7 +307,10 @@ export const ffiFnMapping: FnMapping< return { status: FnValidationStatus.SUCCESS }; } - return { status: FnValidationStatus.IGNORE }; + return { + status: FnValidationStatus.IGNORE, + messages: ['No disableSslVerification or timeout set'], + }; }, }, }; diff --git a/src/verifier/argumentMapper/index.ts b/src/verifier/argumentMapper/index.ts index aace0dce..2b0079d7 100644 --- a/src/verifier/argumentMapper/index.ts +++ b/src/verifier/argumentMapper/index.ts @@ -1,4 +1,4 @@ -import { FnValidationStatus } from './types'; +import { FnValidationResult, FnValidationStatus } from './types'; import logger, { logCrashAndThrow, logErrorAndThrow } from '../../logger'; import { InternalPactVerifierOptions } from '../types'; import { ffiFnMapping, orderOfExecution } from './arguments'; @@ -15,7 +15,7 @@ export const setupVerification = ( order.map((k) => { const fn = functionsToCall[k]; - const validation = ffiFnMapping[fn].validateAndExecute( + const validation: FnValidationResult = ffiFnMapping[fn].validateAndExecute( ffi, handle, options @@ -36,7 +36,9 @@ export const setupVerification = ( break; default: logCrashAndThrow( - `the ffi function '${fn}' returned the following unrecognised validation signal: '${validation.status}'` + `the ffi function '${fn}' returned the following unrecognised validation signal: '${ + (validation as FnValidationResult).status + }'` ); } }); diff --git a/src/verifier/argumentMapper/types.ts b/src/verifier/argumentMapper/types.ts index 30b777f9..2b0efc5c 100644 --- a/src/verifier/argumentMapper/types.ts +++ b/src/verifier/argumentMapper/types.ts @@ -29,7 +29,21 @@ export enum FnValidationStatus { FAIL = 2, } -type FnValidationResult = { - status: FnValidationStatus; - messages?: string[]; +type FnValidationResultSuccess = { + status: FnValidationStatus.SUCCESS; }; + +type FnValidationResultFail = { + status: FnValidationStatus.FAIL; + messages: string[]; +}; + +type FnValidationResultIgnore = { + status: FnValidationStatus.IGNORE; + messages: string[]; +}; + +export type FnValidationResult = + | FnValidationResultSuccess + | FnValidationResultFail + | FnValidationResultIgnore;