Skip to content

Commit ade4490

Browse files
committed
Add more descriptive error messages for if artifact name provided as only whitespace
1 parent a6724ee commit ade4490

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/digest/digest.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func DirSha256(dirPath string, excludePaths []string, logger *logger.Logger) (st
3535
logger.Debug("calculating fingerprint for path [%s] -- excluding paths: %s", dirPath, excludePaths)
3636
info, err := os.Stat(dirPath)
3737
if err != nil {
38+
if dirPath == " " {
39+
return "", fmt.Errorf("%s. The directory path is '%s'. https://docs.kosli.com/faq/", err, dirPath)
40+
}
3841
return "", err
3942
}
4043
if !info.IsDir() {
@@ -83,6 +86,9 @@ func OciSha256(artifactName string, registryUsername string, registryPassword st
8386
// Parse image reference
8487
ref, err := docker.ParseReference(imageName)
8588
if err != nil {
89+
if artifactName == " " {
90+
return "", fmt.Errorf("%w. The artifact name is '%s'. https://docs.kosli.com/faq/", err, artifactName)
91+
}
8692
return "", fmt.Errorf("failed to parse image reference for %s: %w", imageName, err)
8793
}
8894

@@ -171,6 +177,9 @@ func FileSha256(filepath string) (string, error) {
171177
hasher := sha256.New()
172178
f, err := os.Open(filepath)
173179
if err != nil {
180+
if filepath == " " {
181+
return "", fmt.Errorf("%s. The filename is '%s'. https://docs.kosli.com/faq/", err, filepath)
182+
}
174183
return "", err
175184
}
176185
defer f.Close()
@@ -191,6 +200,9 @@ func DockerImageSha256(imageID string) (string, error) {
191200
}
192201
imageInspect, _, err := cli.ImageInspectWithRaw(context.Background(), imageID)
193202
if err != nil {
203+
if imageID == " " {
204+
return "", fmt.Errorf("%s. The image ID is '%s'. https://docs.kosli.com/faq/", err, imageID)
205+
}
194206
return "", err
195207
}
196208
repoDigests := imageInspect.RepoDigests

0 commit comments

Comments
 (0)