Skip to content

Commit fd14a82

Browse files
committed
Improved logging for image inspect errors
1 parent 19397f9 commit fd14a82

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Notable changes.
44

55
## February 2026
66

7+
### [0.83.2]
8+
- Improved logging for image inspect errors. (https://github.com/devcontainers/cli/pull/1152)
9+
710
### [0.83.1]
811
- Bump tar from 7.5.6 to 7.5.7. (https://github.com/devcontainers/cli/pull/1140)
912

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@devcontainers/cli",
33
"description": "Dev Containers CLI",
4-
"version": "0.83.1",
4+
"version": "0.83.2",
55
"bin": {
66
"devcontainer": "devcontainer.js"
77
},

src/spec-node/utils.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,28 +243,42 @@ export function isBuildKitImagePolicyError(err: any): boolean {
243243
export async function inspectDockerImage(params: DockerResolverParameters | DockerCLIParameters, imageName: string, pullImageOnError: boolean) {
244244
try {
245245
return await inspectImage(params, imageName);
246-
} catch (err) {
246+
} catch (inspectErr) {
247+
const output = 'cliHost' in params ? params.output : params.common.output;
247248
if (!pullImageOnError) {
248-
throw err;
249+
logErrorStdoutStderr(inspectErr, output);
250+
throw inspectErr;
249251
}
250-
const output = 'cliHost' in params ? params.output : params.common.output;
251252
try {
252253
return await inspectImageInRegistry(output, params.platformInfo, imageName);
253-
} catch (err2) {
254-
output.write(`Error fetching image details: ${err2?.message}`);
254+
} catch (inspectErr2) {
255+
output.write(`Error fetching image details: ${inspectErr2?.message}`, LogLevel.Info);
255256
}
256257
try {
257258
await retry(async () => dockerPtyCLI(params, 'pull', imageName), { maxRetries: 5, retryIntervalMilliseconds: 1000, output });
258-
} catch (_err) {
259-
if (err.stdout) {
260-
output.write(err.stdout.toString());
261-
}
262-
if (err.stderr) {
263-
output.write(toErrorText(err.stderr.toString()));
264-
}
265-
throw err;
259+
} catch (pullErr) {
260+
logErrorStdoutStderr(inspectErr, output);
261+
logErrorStdoutStderr(pullErr, output);
262+
throw pullErr;
263+
}
264+
try {
265+
return await inspectImage(params, imageName);
266+
} catch (inspectErr3) {
267+
logErrorStdoutStderr(inspectErr3, output);
268+
throw inspectErr3;
266269
}
267-
return inspectImage(params, imageName);
270+
}
271+
}
272+
273+
function logErrorStdoutStderr(err: any, output: Log) {
274+
if (err?.message) {
275+
output.write(err.message, LogLevel.Error);
276+
}
277+
if (err?.stdout) {
278+
output.write(err.stdout.toString(), LogLevel.Error);
279+
}
280+
if (err?.stderr) {
281+
output.write(toErrorText(err.stderr.toString()), LogLevel.Error);
268282
}
269283
}
270284

0 commit comments

Comments
 (0)