Merge pull request #84 from actions/sgoedecke/better-error-logging

Log specific error even if it is not an Error
This commit is contained in:
Sean Goedecke
2025-08-05 09:28:24 +10:00
committed by GitHub
4 changed files with 21 additions and 6 deletions
+13 -3
View File
@@ -94,6 +94,11 @@ vi.mock('../src/inference.js', () => ({
vi.mock('@actions/core', () => core)
// Mock process.exit to prevent it from actually exiting during tests
const mockProcessExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called')
})
// The module being tested should be imported dynamically. This ensures that the
// mocks are used in place of any actual dependencies.
const {run} = await import('../src/main.js')
@@ -102,6 +107,7 @@ describe('main.ts', () => {
// Reset all mocks before each test
beforeEach(() => {
vi.clearAllMocks()
mockProcessExit.mockClear()
// Remove any existing GITHUB_TOKEN
delete process.env.GITHUB_TOKEN
@@ -129,9 +135,11 @@ describe('main.ts', () => {
'prompt-file': '',
})
await run()
// Expect the run function to throw due to process.exit being mocked
await expect(run()).rejects.toThrow('process.exit called')
expect(core.setFailed).toHaveBeenNthCalledWith(1, 'Neither prompt-file nor prompt was set')
expect(core.setFailed).toHaveBeenCalledWith('Neither prompt-file nor prompt was set')
expect(mockProcessExit).toHaveBeenCalledWith(1)
})
it('uses simple inference when MCP is disabled', async () => {
@@ -251,8 +259,10 @@ describe('main.ts', () => {
'prompt-file': promptFile,
})
await run()
// Expect the run function to throw due to process.exit being mocked
await expect(run()).rejects.toThrow('process.exit called')
expect(core.setFailed).toHaveBeenCalledWith(`File for prompt-file was not found: ${promptFile}`)
expect(mockProcessExit).toHaveBeenCalledWith(1)
})
})
Generated Vendored
+3 -1
View File
@@ -52162,8 +52162,10 @@ async function run() {
coreExports.setFailed(error.message);
}
else {
coreExports.setFailed('An unexpected error occurred');
coreExports.setFailed(`An unexpected error occurred: ${JSON.stringify(error, null, 2)}`);
}
// Force exit to prevent hanging on open connections
process.exit(1);
}
}
function tempDir() {
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -94,8 +94,11 @@ export async function run(): Promise<void> {
if (error instanceof Error) {
core.setFailed(error.message)
} else {
core.setFailed('An unexpected error occurred')
core.setFailed(`An unexpected error occurred: ${JSON.stringify(error, null, 2)}`)
}
// Force exit to prevent hanging on open connections
process.exit(1)
}
}