mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 16:04:23 +00:00
Unify errors
This commit is contained in:
@@ -5,14 +5,13 @@ import (
|
|||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrKeyRequired = errors.New("encryption key is required")
|
ErrKeyRequired = fmt.Errorf("encryption key is required")
|
||||||
ErrInvalidKeySize = errors.New("encryption key must be 32 bytes (256 bits) when decoded")
|
ErrInvalidKeySize = fmt.Errorf("encryption key must be 32 bytes (256 bits) when decoded")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Crypto struct {
|
type Crypto struct {
|
||||||
@@ -102,7 +101,7 @@ func (c *Crypto) Decrypt(ciphertext string) (string, error) {
|
|||||||
|
|
||||||
nonceSize := gcm.NonceSize()
|
nonceSize := gcm.NonceSize()
|
||||||
if len(data) < nonceSize {
|
if len(data) < nonceSize {
|
||||||
return "", errors.New("ciphertext too short")
|
return "", fmt.Errorf("ciphertext too short")
|
||||||
}
|
}
|
||||||
|
|
||||||
nonce, ciphertextBytes := data[:nonceSize], data[nonceSize:]
|
nonce, ciphertextBytes := data[:nonceSize], data[nonceSize:]
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -114,7 +113,7 @@ func (fs *FileSystem) FindFileByName(userID, workspaceID int, filename string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(foundPaths) == 0 {
|
if len(foundPaths) == 0 {
|
||||||
return nil, errors.New("file not found")
|
return nil, fmt.Errorf("file not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundPaths, nil
|
return foundPaths, nil
|
||||||
@@ -171,7 +170,7 @@ func (fs *FileSystem) GetFileStats(userID, workspaceID int) (*FileCountStats, er
|
|||||||
|
|
||||||
// Check if workspace exists
|
// Check if workspace exists
|
||||||
if _, err := os.Stat(workspacePath); os.IsNotExist(err) {
|
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)
|
return fs.countFilesInPath(workspacePath)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
"novamd/internal/gitutils"
|
"novamd/internal/gitutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ func (fs *FileSystem) DisableGitRepo(userID, workspaceID int) {
|
|||||||
func (fs *FileSystem) StageCommitAndPush(userID, workspaceID int, message string) error {
|
func (fs *FileSystem) StageCommitAndPush(userID, workspaceID int, message string) error {
|
||||||
repo, ok := fs.getGitRepo(userID, workspaceID)
|
repo, ok := fs.getGitRepo(userID, workspaceID)
|
||||||
if !ok {
|
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 {
|
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 {
|
func (fs *FileSystem) Pull(userID, workspaceID int) error {
|
||||||
repo, ok := fs.getGitRepo(userID, workspaceID)
|
repo, ok := fs.getGitRepo(userID, workspaceID)
|
||||||
if !ok {
|
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()
|
return repo.Pull()
|
||||||
|
|||||||
Reference in New Issue
Block a user