include more detail in error logging (#58)

Signed-off-by: Brian DeHamer <[email protected]>
This commit is contained in:
Brian DeHamer
2024-05-09 12:34:01 -07:00
committed by GitHub
parent 9b22bf5c9f
commit b0d8b47eb7
3 changed files with 26 additions and 9 deletions
+6 -4
View File
@@ -116,7 +116,9 @@ describe('action', () => {
expect(runMock).toHaveReturned() expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith( expect(setFailedMock).toHaveBeenCalledWith(
expect.stringMatching(/missing "id-token" permission/) new Error(
'missing "id-token" permission. Please add "permissions: id-token: write" to your workflow.'
)
) )
}) })
}) })
@@ -131,9 +133,7 @@ describe('action', () => {
expect(runMock).toHaveReturned() expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith( expect(setFailedMock).toHaveBeenCalledWith(
expect.stringMatching( new Error('One of subject-path or subject-digest must be provided')
/one of subject-path or subject-digest must be provided/i
)
) )
}) })
}) })
@@ -330,8 +330,10 @@ describe('action', () => {
expect(runMock).toHaveReturned() expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith( expect(setFailedMock).toHaveBeenCalledWith(
new Error(
'Too many subjects specified. The maximum number of subjects is 64.' 'Too many subjects specified. The maximum number of subjects is 64.'
) )
)
}) })
}) })
}) })
Generated Vendored
+8 -2
View File
@@ -79849,6 +79849,7 @@ const endpoints_1 = __nccwpck_require__(69112);
const predicate_1 = __nccwpck_require__(72103); const predicate_1 = __nccwpck_require__(72103);
const subject_1 = __nccwpck_require__(95206); const subject_1 = __nccwpck_require__(95206);
const COLOR_CYAN = '\x1B[36m'; const COLOR_CYAN = '\x1B[36m';
const COLOR_GRAY = '\x1B[38;5;244m';
const COLOR_DEFAULT = '\x1B[39m'; const COLOR_DEFAULT = '\x1B[39m';
const ATTESTATION_FILE_NAME = 'attestation.jsonl'; const ATTESTATION_FILE_NAME = 'attestation.jsonl';
const MAX_SUBJECT_COUNT = 64; const MAX_SUBJECT_COUNT = 64;
@@ -79901,11 +79902,12 @@ async function run() {
} }
catch (err) { catch (err) {
// Fail the workflow run if an error occurs // Fail the workflow run if an error occurs
core.setFailed(err instanceof Error ? err.message : /* istanbul ignore next */ `${err}`); core.setFailed(err instanceof Error ? err : /* istanbul ignore next */ `${err}`);
// Log the cause of the error if one is available
/* istanbul ignore if */ /* istanbul ignore if */
if (err instanceof Error && 'cause' in err) { if (err instanceof Error && 'cause' in err) {
const innerErr = err.cause; const innerErr = err.cause;
core.debug(innerErr instanceof Error ? innerErr.message : `${innerErr}}`); core.info(mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`));
} }
} }
} }
@@ -79951,7 +79953,11 @@ const createAttestation = async (subject, predicate, sigstoreInstance) => {
} }
return attestation; return attestation;
}; };
// Emphasis string using ANSI color codes
const highlight = (str) => `${COLOR_CYAN}${str}${COLOR_DEFAULT}`; const highlight = (str) => `${COLOR_CYAN}${str}${COLOR_DEFAULT}`;
// De-emphasize string using ANSI color codes
/* istanbul ignore next */
const mute = (str) => `${COLOR_GRAY}${str}${COLOR_DEFAULT}`;
const tempDir = () => { const tempDir = () => {
const basePath = process.env['RUNNER_TEMP']; const basePath = process.env['RUNNER_TEMP'];
/* istanbul ignore if */ /* istanbul ignore if */
+11 -2
View File
@@ -13,6 +13,7 @@ type SigstoreInstance = 'public-good' | 'github'
type AttestedSubject = { subject: Subject; attestationID: string } type AttestedSubject = { subject: Subject; attestationID: string }
const COLOR_CYAN = '\x1B[36m' const COLOR_CYAN = '\x1B[36m'
const COLOR_GRAY = '\x1B[38;5;244m'
const COLOR_DEFAULT = '\x1B[39m' const COLOR_DEFAULT = '\x1B[39m'
const ATTESTATION_FILE_NAME = 'attestation.jsonl' const ATTESTATION_FILE_NAME = 'attestation.jsonl'
@@ -86,13 +87,16 @@ export async function run(): Promise<void> {
} catch (err) { } catch (err) {
// Fail the workflow run if an error occurs // Fail the workflow run if an error occurs
core.setFailed( core.setFailed(
err instanceof Error ? err.message : /* istanbul ignore next */ `${err}` err instanceof Error ? err : /* istanbul ignore next */ `${err}`
) )
// Log the cause of the error if one is available
/* istanbul ignore if */ /* istanbul ignore if */
if (err instanceof Error && 'cause' in err) { if (err instanceof Error && 'cause' in err) {
const innerErr = err.cause const innerErr = err.cause
core.debug(innerErr instanceof Error ? innerErr.message : `${innerErr}}`) core.info(
mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`)
)
} }
} }
} }
@@ -156,8 +160,13 @@ const createAttestation = async (
return attestation return attestation
} }
// Emphasis string using ANSI color codes
const highlight = (str: string): string => `${COLOR_CYAN}${str}${COLOR_DEFAULT}` const highlight = (str: string): string => `${COLOR_CYAN}${str}${COLOR_DEFAULT}`
// De-emphasize string using ANSI color codes
/* istanbul ignore next */
const mute = (str: string): string => `${COLOR_GRAY}${str}${COLOR_DEFAULT}`
const tempDir = (): string => { const tempDir = (): string => {
const basePath = process.env['RUNNER_TEMP'] const basePath = process.env['RUNNER_TEMP']