Skip to content

Commit

Permalink
fix: Add error messages to the ignored option debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJones committed Oct 25, 2022
1 parent 150ac95 commit 8c8386d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
55 changes: 45 additions & 10 deletions src/verifier/argumentMapper/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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'],
};
},
},
};
8 changes: 5 additions & 3 deletions src/verifier/argumentMapper/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand All @@ -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
}'`
);
}
});
Expand Down
20 changes: 17 additions & 3 deletions src/verifier/argumentMapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8c8386d

Please sign in to comment.