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:
+13
-3
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
+3
-1
@@ -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() {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+4
-1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user