Skip to content

include more detail in error logging #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ describe('action', () => {

expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith(
expect.stringMatching(/missing "id-token" permission/)
new Error(
'missing "id-token" permission. Please add "permissions: id-token: write" to your workflow.'
)
)
})
})
Expand All @@ -131,9 +133,7 @@ describe('action', () => {

expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith(
expect.stringMatching(
/one of subject-path or subject-digest must be provided/i
)
new Error('One of subject-path or subject-digest must be provided')
)
})
})
Expand Down Expand Up @@ -330,7 +330,9 @@ describe('action', () => {

expect(runMock).toHaveReturned()
expect(setFailedMock).toHaveBeenCalledWith(
'Too many subjects specified. The maximum number of subjects is 64.'
new Error(
'Too many subjects specified. The maximum number of subjects is 64.'
)
)
})
})
Expand Down
10 changes: 8 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SigstoreInstance = 'public-good' | 'github'
type AttestedSubject = { subject: Subject; attestationID: string }

const COLOR_CYAN = '\x1B[36m'
const COLOR_GRAY = '\x1B[38;5;244m'
const COLOR_DEFAULT = '\x1B[39m'
const ATTESTATION_FILE_NAME = 'attestation.jsonl'

Expand Down Expand Up @@ -86,13 +87,16 @@ export async function run(): Promise<void> {
} catch (err) {
// Fail the workflow run if an error occurs
core.setFailed(
err instanceof Error ? err.message : /* istanbul ignore next */ `${err}`
err instanceof Error ? err : /* istanbul ignore next */ `${err}`
Comment on lines -89 to +90
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the entire Error object causes the error class to be displayed in the output.

)

// Log the cause of the error if one is available
/* istanbul ignore if */
if (err instanceof Error && 'cause' in err) {
const innerErr = err.cause
core.debug(innerErr instanceof Error ? innerErr.message : `${innerErr}}`)
core.info(
mute(innerErr instanceof Error ? innerErr.toString() : `${innerErr}`)
)
Comment on lines -95 to +99
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching from debug to info so the inner error is always displayed (if available).

}
}
}
Expand Down Expand Up @@ -156,8 +160,13 @@ const createAttestation = async (
return attestation
}

// Emphasis string using ANSI color codes
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 basePath = process.env['RUNNER_TEMP']

Expand Down
Loading