From 118591df62078270b534232736cef2f867e4c97b Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sat, 9 Nov 2024 23:12:52 +0100 Subject: [PATCH] Unify errors --- backend/internal/crypto/crypto.go | 7 +++---- backend/internal/filesystem/files.go | 5 ++--- backend/internal/filesystem/git.go | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/backend/internal/crypto/crypto.go b/backend/internal/crypto/crypto.go index 1b08245..76cf338 100644 --- a/backend/internal/crypto/crypto.go +++ b/backend/internal/crypto/crypto.go @@ -5,14 +5,13 @@ import ( "crypto/cipher" "crypto/rand" "encoding/base64" - "errors" "fmt" "io" ) var ( - ErrKeyRequired = errors.New("encryption key is required") - ErrInvalidKeySize = errors.New("encryption key must be 32 bytes (256 bits) when decoded") + ErrKeyRequired = fmt.Errorf("encryption key is required") + ErrInvalidKeySize = fmt.Errorf("encryption key must be 32 bytes (256 bits) when decoded") ) type Crypto struct { @@ -102,7 +101,7 @@ func (c *Crypto) Decrypt(ciphertext string) (string, error) { nonceSize := gcm.NonceSize() if len(data) < nonceSize { - return "", errors.New("ciphertext too short") + return "", fmt.Errorf("ciphertext too short") } nonce, ciphertextBytes := data[:nonceSize], data[nonceSize:] diff --git a/backend/internal/filesystem/files.go b/backend/internal/filesystem/files.go index 3857708..9b876d8 100644 --- a/backend/internal/filesystem/files.go +++ b/backend/internal/filesystem/files.go @@ -3,7 +3,6 @@ package filesystem import ( - "errors" "fmt" "os" "path/filepath" @@ -114,7 +113,7 @@ func (fs *FileSystem) FindFileByName(userID, workspaceID int, filename string) ( } if len(foundPaths) == 0 { - return nil, errors.New("file not found") + return nil, fmt.Errorf("file not found") } return foundPaths, nil @@ -171,7 +170,7 @@ func (fs *FileSystem) GetFileStats(userID, workspaceID int) (*FileCountStats, er // Check if workspace exists if _, err := os.Stat(workspacePath); os.IsNotExist(err) { - return nil, errors.New("workspace directory does not exist") + return nil, fmt.Errorf("workspace directory does not exist") } return fs.countFilesInPath(workspacePath) diff --git a/backend/internal/filesystem/git.go b/backend/internal/filesystem/git.go index 6c97a6f..de83ad9 100644 --- a/backend/internal/filesystem/git.go +++ b/backend/internal/filesystem/git.go @@ -1,7 +1,7 @@ package filesystem import ( - "errors" + "fmt" "novamd/internal/gitutils" ) @@ -29,7 +29,7 @@ func (fs *FileSystem) DisableGitRepo(userID, workspaceID int) { func (fs *FileSystem) StageCommitAndPush(userID, workspaceID int, message string) error { repo, ok := fs.getGitRepo(userID, workspaceID) if !ok { - return errors.New("git settings not configured for this workspace") + return fmt.Errorf("git settings not configured for this workspace") } if err := repo.Commit(message); err != nil { @@ -43,7 +43,7 @@ func (fs *FileSystem) StageCommitAndPush(userID, workspaceID int, message string func (fs *FileSystem) Pull(userID, workspaceID int) error { repo, ok := fs.getGitRepo(userID, workspaceID) if !ok { - return errors.New("git settings not configured for this workspace") + return fmt.Errorf("git settings not configured for this workspace") } return repo.Pull()