Skip to content

Commit b0d8b47

Browse files
authored
include more detail in error logging (#58)
Signed-off-by: Brian DeHamer <bdehamer@github.com>
1 parent 9b22bf5 commit b0d8b47

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

__tests__/main.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ describe('action', () => {
116116

117117
expect(runMock).toHaveReturned()
118118
expect(setFailedMock).toHaveBeenCalledWith(
119-
expect.stringMatching(/missing "id-token" permission/)
119+
new Error(
120+
'missing "id-token" permission. Please add "permissions: id-token: write" to your workflow.'
121+
)
120122
)
121123
})
122124
})
@@ -131,9 +133,7 @@ describe('action', () => {
131133

132134
expect(runMock).toHaveReturned()
133135
expect(setFailedMock).toHaveBeenCalledWith(
134-
expect.stringMatching(
135-
/one of subject-path or subject-digest must be provided/i
136-
)
136+
new Error('One of subject-path or subject-digest must be provided')
137137
)
138138
})
139139
})
@@ -330,7 +330,9 @@ describe('action', () => {
330330

331331
expect(runMock).toHaveReturned()
332332
expect(setFailedMock).toHaveBeenCalledWith(
333-
'Too many subjects specified. The maximum number of subjects is 64.'
333+
new Error(
334+
'Too many subjects specified. The maximum number of subjects is 64.'
335+
)
334336
)
335337
})
336338
})

dist/index.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type SigstoreInstance = 'public-good' | 'github'
1313
type AttestedSubject = { subject: Subject; attestationID: string }
1414

1515
const COLOR_CYAN = '\x1B[36m'
16+
const COLOR_GRAY = '\x1B[38;5;244m'
1617
const COLOR_DEFAULT = '\x1B[39m'
1718
const ATTESTATION_FILE_NAME = 'attestation.jsonl'
1819

@@ -86,13 +87,16 @@ export async function run(): Promise<void> {
8687
} catch (err) {
8788
// Fail the workflow run if an error occurs
8889
core.setFailed(
89-
err instanceof Error ? err.message : /* istanbul ignore next */ `${err}`
90+
err instanceof Error ? err : /* istanbul ignore next */ `${err}`
9091
)
9192

93+
// Log the cause of the error if one is available
9294
/* istanbul ignore if */
9395
if (err instanceof Error && 'cause' in err) {
9496
const innerErr = err.cause
95-
core.debug(innerErr instanceof Error ? innerErr.message : `${innerErr}}`)
97+
core.info(
98+
mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`)
99+
)
96100
}
97101
}
98102
}
@@ -156,8 +160,13 @@ const createAttestation = async (
156160
return attestation
157161
}
158162

163+
// Emphasis string using ANSI color codes
159164
const highlight = (str: string): string => `${COLOR_CYAN}${str}${COLOR_DEFAULT}`
160165

166+
// De-emphasize string using ANSI color codes
167+
/* istanbul ignore next */
168+
const mute = (str: string): string => `${COLOR_GRAY}${str}${COLOR_DEFAULT}`
169+
161170
const tempDir = (): string => {
162171
const basePath = process.env['RUNNER_TEMP']
163172

0 commit comments

Comments
 (0)