From ed0f8fd922d28ca351e8e38ad82e64567b46e930 Mon Sep 17 00:00:00 2001 From: Fernando Salas Date: Thu, 25 Apr 2024 17:09:33 -0500 Subject: [PATCH] feat(archive): Migrate errors to constants Unwrapped errors: ErrTarFileNoDest and ErrTarFileWriteDir --- archive/archive.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/archive/archive.go b/archive/archive.go index 64bfcc5fd..587b9eab4 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -21,6 +21,11 @@ import ( "kraftkit.sh/log" ) +var ( + ErrTarFileNoDest = fmt.Errorf("cannot tar file with no specified destination") + ErrTarFileWriteDir = fmt.Errorf("attempting to use TarFileWriter with directory") +) + // bufPool is a pool of byte buffers that can be reused for copying content // between files. var bufPool = sync.Pool{ @@ -38,12 +43,12 @@ func TarFileWriter(ctx context.Context, src, dst string, tw *tar.Writer, opts .. dst = filepath.ToSlash(dst) if dst == "" { - return fmt.Errorf("cannot tar file with no specified destination") - } else if dst[0] == filepath.Separator { + return ErrTarFileNoDest + } else if dst[0] == filepath.Separator { dst = dst[1:] } if strings.HasSuffix(dst, string(filepath.Separator)) { - return fmt.Errorf("attempting to use TarFileWriter with directory") + return ErrTarFileWriteDir } aopts := ArchiveOptions{}