diff --git a/dist/index.js b/dist/index.js index 5963160..aceca09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35,6 +35,13 @@ async function run(dependencies = {}) { if (errorOutput) { core.warning(`govulncheck stderr: ${errorOutput}`); + + // Check for critical errors that indicate govulncheck couldn't run properly + if (errorOutput.includes('missing go.sum entry') || + errorOutput.includes('could not import') || + errorOutput.includes('invalid package name')) { + throw new Error(`govulncheck failed due to missing dependencies. Please run 'go mod tidy' to update go.mod and go.sum files.\n\nError: ${errorOutput}`); + } } // Log raw output for debugging diff --git a/index.js b/index.js index 96a33a7..2fffab8 100644 --- a/index.js +++ b/index.js @@ -29,6 +29,13 @@ async function run(dependencies = {}) { if (errorOutput) { core.warning(`govulncheck stderr: ${errorOutput}`); + + // Check for critical errors that indicate govulncheck couldn't run properly + if (errorOutput.includes('missing go.sum entry') || + errorOutput.includes('could not import') || + errorOutput.includes('invalid package name')) { + throw new Error(`govulncheck failed due to missing dependencies. Please run 'go mod tidy' to update go.mod and go.sum files.\n\nError: ${errorOutput}`); + } } // Log raw output for debugging diff --git a/test/index.test.js b/test/index.test.js index 5d3ee04..d6b63cb 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -174,6 +174,34 @@ describe('GitHub Action Integration', () => { ); }); + it('should fail when go.sum is missing', async () => { + mockGovulncheck.run.mockResolvedValue({ + output: '{"config": {}}', + errorOutput: 'missing go.sum entry for module providing package golang.org/x/net/html', + exitCode: 1 + }); + + await expect(run({ + govulncheck: mockGovulncheck, + parser: mockParser, + annotator: mockAnnotator + })).rejects.toThrow('govulncheck failed due to missing dependencies'); + }); + + it('should fail when imports cannot be resolved', async () => { + mockGovulncheck.run.mockResolvedValue({ + output: '{"config": {}}', + errorOutput: 'could not import golang.org/x/net/html (invalid package name: "")', + exitCode: 1 + }); + + await expect(run({ + govulncheck: mockGovulncheck, + parser: mockParser, + annotator: mockAnnotator + })).rejects.toThrow('govulncheck failed due to missing dependencies'); + }); + it('should handle errors and set action as failed', async () => { const error = new Error('Failed to install govulncheck'); mockGovulncheck.install.mockRejectedValue(error);