Skip to content

Commit 2713313

Browse files
authored
fix: dont send empty image references list to exhort (#845)
1 parent def2904 commit 2713313

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/imageAnalysis.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from 'vscode';
66
import { globalConfig } from './config';
77
import { imageAnalysisService } from './exhortServices';
88
import { StatusMessages, Titles } from './constants';
9+
import * as templates from './template';
910
import { Options } from '@trustification/exhort-javascript-api';
1011
import { updateCurrentWebviewPanel } from './rhda';
1112
import { buildLogErrorMessage } from './utils';
@@ -162,6 +163,15 @@ class DockerImageAnalysis {
162163
try {
163164
this.outputChannel.info(`generating image analysis report for "${this.filePath}"`);
164165

166+
// Check if no images were found
167+
if (this.images.length === 0) {
168+
this.outputChannel.info(`no images found in "${this.filePath}"`);
169+
updateCurrentWebviewPanel(templates.NO_IMAGES_TEMPLATE);
170+
p.report({ message: StatusMessages.WIN_FAILURE_DEPENDENCY_ANALYSIS });
171+
this.imageAnalysisReportHtml = templates.NO_IMAGES_TEMPLATE;
172+
return;
173+
}
174+
165175
const options: IOptions = {
166176
'RHDA_TOKEN': globalConfig.telemetryId ?? '',
167177
'RHDA_SOURCE': globalConfig.utmSource,

src/imageAnalysis/diagnostics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ async function performDiagnostics(diagnosticFilePath: Uri, contents: string, pro
103103
};
104104

105105
const images = provider.collect(contents);
106+
if (images.length === 0) {
107+
outputChannelDep.warn(`no image references found in ${diagnosticFilePath}`);
108+
return;
109+
}
106110
const imageMap = new ImageMap(images, options);
107111

108112
const diagnosticsPipeline = new DiagnosticsPipeline(imageMap, diagnosticFilePath);

src/template.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,50 @@ export const ERROR_TEMPLATE = `<!DOCTYPE html>
285285
</div>
286286
</body>
287287
</html>`;
288+
289+
export const NO_IMAGES_TEMPLATE = `<!DOCTYPE html>
290+
<html lang="en">
291+
<head>
292+
<meta charset="utf-8"/>
293+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
294+
<style>
295+
html,body {
296+
width: 99%;
297+
height: 99%;
298+
font-size: 16px;
299+
font-family: system-ui, -apple-system, sans-serif;
300+
}
301+
302+
body {
303+
background: #ffffff;
304+
display: flex;
305+
align-items: center;
306+
justify-content: center;
307+
margin: 0;
308+
padding: 20px;
309+
}
310+
311+
.message-container {
312+
text-align: center;
313+
max-width: 500px;
314+
}
315+
316+
h2 {
317+
color: #333;
318+
margin-bottom: 16px;
319+
}
320+
321+
p {
322+
color: #666;
323+
line-height: 1.5;
324+
}
325+
</style>
326+
</head>
327+
<body>
328+
<div class="message-container">
329+
<h2>No Container Images Found</h2>
330+
<p>This Dockerfile or Containerfile does not contain any image references to analyze.</p>
331+
<p>Add <code>FROM</code> statements with base images to perform stack analysis.</p>
332+
</div>
333+
</body>
334+
</html>`;

0 commit comments

Comments
 (0)