main: return exit code 2 when an input is not found

This commit makes skopeo return a different exit code when an
input is not found. The use case is `osbuild` which uses skopeo
to inspect images and it would be nice to differenciate between
an image that is not found and general skopeo errors (or errors
like network issues etc).

I picked exit code `2` for `not found` because it is also the value
of `ENOENT`.

Man page and a test are added.

Signed-off-by: Michael Vogt <mvogt@redhat.com>
This commit is contained in:
Michael Vogt
2024-02-26 12:25:32 +01:00
committed by Michael Vogt
parent d5ac962b5e
commit 16b6f0ade5
7 changed files with 46 additions and 24 deletions

View File

@@ -129,4 +129,11 @@ END_EXPECT
expect_output --from="$repo_tags" "" "inspect --no-tags was expected to return empty RepoTags[]"
}
@test "inspect: image unknown" {
# non existing image
run_skopeo 2 inspect containers-storage:non-existing-tag
expect_output --substring "identifier is not an image" \
"skopeo inspect containers-storage:010101010101"
}
# vim: filetype=sh

View File

@@ -40,7 +40,7 @@ function setup() {
expect_output --substring "authentication required"
# Correct creds, but no such image
run_skopeo 1 inspect --tls-verify=false --creds=$testuser:$testpassword \
run_skopeo 2 inspect --tls-verify=false --creds=$testuser:$testpassword \
docker://localhost:5000/nonesuch
expect_output --substring "manifest unknown"

View File

@@ -24,7 +24,7 @@ function setup() {
run_skopeo delete --tls-verify=false $localimg
# make sure image is removed from registry
expected_rc=1
expected_rc=2
run_skopeo $expected_rc inspect --tls-verify=false $localimg
}