Skip to content

Commit

Permalink
Relegate unhelpful container id message to core.info instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Gordon committed Mar 8, 2022
1 parent 2e5a468 commit 0edc582
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/container-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('ContainerService', () => {

test('raises an exception', async () => {
await expect(ContainerService.run(container)).rejects.toThrow(
/Failure running container/
/The updater encountered one or more errors/
)
})
})
Expand Down
37 changes: 36 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path'
import * as core from '@actions/core'
import {Context} from '@actions/github/lib/context'
import {ApiClient} from '../src/api-client'
import {ContainerRuntimeError} from '../src/container-service'
import {Updater, UpdaterFetchError} from '../src/updater'
import {ImageService} from '../src/image-service'
import * as inputs from '../src/inputs'
Expand Down Expand Up @@ -242,7 +243,41 @@ describe('run', () => {
})
})

describe('when there is an error running the update', () => {
describe('when there the update container exits with an error signal', () => {
beforeEach(() => {
jest
.spyOn(Updater.prototype, 'runUpdater')
.mockImplementationOnce(
jest.fn(async () =>
Promise.reject(new ContainerRuntimeError('the container melted'))
)
)

context = new Context()
})

test('it fails the workflow', async () => {
await run(context)

expect(core.setFailed).toHaveBeenCalledWith(
`Dependabot encountered an error performing the update\n\nError: the container melted\n\nFor more information see: https://test.dev/foo/bar/network/updates/1 (write access required)`
)
})

test('it relays a failure message to the dependabot service', async () => {
await run(context)

expect(reportJobErrorSpy).toHaveBeenCalledWith({
'error-type': 'actions_workflow_updater',
'error-details': {
'action-error': 'the container melted'
}
})
expect(markJobAsProcessedSpy).toHaveBeenCalled()
})
})

describe('when there is an unexpected error running the update', () => {
beforeEach(() => {
jest
.spyOn(Updater.prototype, 'runUpdater')
Expand Down
5 changes: 3 additions & 2 deletions src/container-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {pack} from 'tar-stream'
import {FileFetcherInput, FileUpdaterInput, ProxyConfig} from './config-types'
import {outStream, errStream} from './utils'

class ContainerRuntimeError extends Error {}
export class ContainerRuntimeError extends Error {}

export const ContainerService = {
async storeInput(
Expand Down Expand Up @@ -50,8 +50,9 @@ export const ContainerService = {
if (outcome.StatusCode === 0) {
return true
} else {
core.info(`Failure running container ${container.id}`)
throw new ContainerRuntimeError(
`Failure running container ${container.id}`
'The updater encountered one or more errors.'
)
}
} finally {
Expand Down

0 comments on commit 0edc582

Please sign in to comment.