diff --git a/store/bolt.go b/store/bolt.go index 6d25dfb..e1f1b75 100644 --- a/store/bolt.go +++ b/store/bolt.go @@ -65,7 +65,7 @@ func (s *BoltStore) GetFile(id string) (*pb.File, error) { return nil, fmt.Errorf("error getting file: %w", err) } if data == nil { - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } err := proto.Unmarshal(data, &file) @@ -98,7 +98,7 @@ func (s *BoltStore) DeleteFile(id string) error { bkt := t.Bucket(bktKey) data := bkt.Get([]byte(id)) if data == nil { - return ErrNoSuchFile + return ErrNoSuchItem } return bkt.Delete([]byte(id)) }) @@ -140,7 +140,7 @@ func (s *BoltStore) GetCertificate(id string) (*x509.Certificate, error) { return nil, err } if raw == nil { - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } cert, err := x509.ParseCertificate(raw) @@ -269,5 +269,5 @@ func (s *BoltStore) GetUserByUsername(username string) (*pb.User, error) { if user.Username == username { return &user, nil } - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } diff --git a/store/filesystem.go b/store/filesystem.go index 6401207..0953adc 100644 --- a/store/filesystem.go +++ b/store/filesystem.go @@ -27,7 +27,7 @@ func (s *FileSystemStore) GetFile(id string) (*pb.File, error) { f, err := os.Open(path) if err != nil { if os.IsNotExist(os.ErrNotExist) { - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } return nil, fmt.Errorf("unable to open file: %w", err) } diff --git a/store/memory.go b/store/memory.go index 0283875..4d24976 100644 --- a/store/memory.go +++ b/store/memory.go @@ -43,7 +43,7 @@ func (s *MemoryStore) GetFile(id string) (*pb.File, error) { return file, nil } - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } func (s *MemoryStore) StoreFile(file *pb.File) (string, error) { @@ -62,7 +62,7 @@ func (s *MemoryStore) DeleteFile(id string) error { s.filesLock.Lock() defer s.filesLock.Unlock() if _, ok := s.files[id]; !ok { - return ErrNoSuchFile + return ErrNoSuchItem } delete(s.files, id) @@ -95,7 +95,7 @@ func (s *MemoryStore) GetCertificate(id string) (*x509.Certificate, error) { data, ok := s.certs[id] if !ok { // TODO: Make separate error, or rename error - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } return x509.ParseCertificate(data) @@ -118,7 +118,7 @@ func (s *MemoryStore) GetKey(id string) (*ecdsa.PrivateKey, error) { defer s.keyLock.RUnlock() data, ok := s.keys[id] if !ok { - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } return x509.ParseECPrivateKey(data) @@ -167,7 +167,7 @@ func (s *MemoryStore) GetUser(id string) (*pb.User, error) { user, ok := s.users[id] if !ok { // TODO: Update error - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } return user, nil } @@ -191,5 +191,5 @@ func (s *MemoryStore) GetUserByUsername(username string) (*pb.User, error) { return user, nil } } - return nil, ErrNoSuchFile + return nil, ErrNoSuchItem } diff --git a/store/store.go b/store/store.go index 7bddcf7..e5687b5 100644 --- a/store/store.go +++ b/store/store.go @@ -8,7 +8,7 @@ import ( "gitea.benny.dog/torjus/ezshare/pb" ) -var ErrNoSuchFile = fmt.Errorf("no such file") +var ErrNoSuchItem = fmt.Errorf("no such item") type FileStore interface { GetFile(id string) (*pb.File, error) diff --git a/store/store_test.go b/store/store_test.go index 52b68b9..6c3e99a 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -68,7 +68,7 @@ func doFileStoreTest(s store.FileStore, t *testing.T) { t.Fatalf("Unable to delete file: %s", err) } - if _, err := s.GetFile(id); err != store.ErrNoSuchFile { + if _, err := s.GetFile(id); err != store.ErrNoSuchItem { t.Fatalf("Getting deleted file returned wrong error: %s", err) } })