Skip to content

Commit df6bb89

Browse files
committed
fix: log error and error stack in exception handler
1 parent e09c75e commit df6bb89

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

lib/analyzer/image-inspector.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,11 @@ async function getImageArchive(
212212

213213
try {
214214
inspectResult = await getInspectResult(docker, targetImage);
215-
} catch {
216-
debug(`${targetImage} does not exist locally, proceeding to pull image.`);
215+
} catch (error) {
216+
debug(
217+
`${targetImage} does not exist locally, proceeding to pull image.`,
218+
error.stack || error,
219+
);
217220
}
218221

219222
if (inspectResult === undefined) {

test/system/plugin.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DepGraph } from "@snyk/dep-graph";
22
import * as plugin from "../../lib";
3+
import * as subProcess from "../../lib/sub-process";
34
import { getFixture } from "../util";
45

56
describe("plugin", () => {
@@ -108,6 +109,35 @@ describe("plugin", () => {
108109
expect(depGraph.rootPkg.version).toEqual("1.19.0");
109110
});
110111

112+
describe("when scanning a locally loaded image", () => {
113+
const imageName = "busybox";
114+
const imageTag = "latest";
115+
const imageNameWithTag = `${imageName}:${imageTag}`;
116+
117+
beforeAll(async () => {
118+
const fixturePath = getFixture([
119+
"../fixtures/docker-archives",
120+
"skopeo-copy/busybox.tar",
121+
]);
122+
await subProcess.execute("docker", ["load", "--input", fixturePath]);
123+
}, 10000); // 10s timeout for loading image
124+
125+
afterAll(async () => {
126+
await subProcess.execute("docker", ["rmi", imageNameWithTag]);
127+
});
128+
129+
test("should successfully scan a local image loaded from a tar archive", async () => {
130+
const pluginResult = await plugin.scan({ path: imageNameWithTag });
131+
const depGraph: DepGraph = pluginResult.scanResults[0].facts.find(
132+
(fact) => fact.type === "depGraph",
133+
)!.data;
134+
135+
expect(depGraph.rootPkg.name).toEqual(`docker-image|${imageName}`);
136+
expect(depGraph.rootPkg.version).toEqual(imageTag);
137+
expect(pluginResult.scanResults[0].identity.type).toEqual("linux");
138+
});
139+
});
140+
111141
test("static scan for Identifier type image (nginx:1.19.0)", async () => {
112142
// This digest resolves to the `1.19.0` tag. We're using the digest to guarantee we always get the correct
113143
// image, no matter on which platform this test is run on.

0 commit comments

Comments
 (0)