Unify errors

This commit is contained in:
2024-11-09 23:12:52 +01:00
parent 7b1da94e8a
commit 118591df62
3 changed files with 8 additions and 10 deletions

View File

@@ -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:]

View File

@@ -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)

View File

@@ -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()