Browse Source

chore: Renaming of Storage Manager errors

Matthias Ladkau 3 years ago
parent
commit
90bd655763

+ 1 - 1
api/v1/blob.go

@@ -468,7 +468,7 @@ func (be *blobEndpoint) HandleGET(w http.ResponseWriter, r *http.Request, resour
 
 		res, err = sm.FetchCached(loc)
 
-		if sme, ok := err.(*storage.StorageManagerError); ok && sme.Type == storage.ErrNotInCache {
+		if sme, ok := err.(*storage.ManagerError); ok && sme.Type == storage.ErrNotInCache {
 			err = sm.Fetch(loc, &ret)
 		} else if err == nil && res != nil {
 			ret = res.([]byte)

+ 1 - 1
cluster/distributedstorage_test.go

@@ -250,7 +250,7 @@ func TestSimpleDataDistribution(t *testing.T) {
 		return
 	}
 
-	if _, err := sm.FetchCached(5); err.(*storage.StorageManagerError).Type != storage.ErrNotInCache {
+	if _, err := sm.FetchCached(5); err.(*storage.ManagerError).Type != storage.ErrNotInCache {
 		t.Error("Unexpected response:", err)
 		return
 	}

+ 1 - 1
ecal/dbfunc/graphql.go

@@ -34,7 +34,7 @@ func (f *GraphQLFunc) Run(instanceID string, vs parser.Scope, is map[string]inte
 	var ret interface{}
 
 	if arglen := len(args); arglen < 2 {
-		err = fmt.Errorf("Function requires at least 2 parameters: partition and query with optionally a map of variables and an operation name.")
+		err = fmt.Errorf("Function requires at least 2 parameters: partition and query with optionally a map of variables and an operation name")
 	}
 
 	if err == nil {

+ 1 - 1
ecal/dbfunc/graphql_test.go

@@ -42,7 +42,7 @@ func TestGraphQL(t *testing.T) {
 	}
 
 	if _, err := q.Run("", nil, nil, 0, []interface{}{""}); err == nil ||
-		err.Error() != "Function requires at least 2 parameters: partition and query with optionally a map of variables and an operation name." {
+		err.Error() != "Function requires at least 2 parameters: partition and query with optionally a map of variables and an operation name" {
 		t.Error(err)
 		return
 	}

+ 18 - 13
ecal/dbfunc/util.go

@@ -41,6 +41,9 @@ func (f *RaiseGraphEventHandledFunc) DocString() (string, error) {
 	return "When handling a graph event, notify the GraphManager of EliasDB that no further action is necessary.", nil
 }
 
+/*
+ErrWebEventHandled is a special error to signal that a web request was handled.
+*/
 var ErrWebEventHandled = fmt.Errorf("Web event handled")
 
 /*
@@ -60,22 +63,24 @@ func (f *RaiseWebEventHandledFunc) Run(instanceID string, vs parser.Scope, is ma
 
 	res := args[0]
 
-	if resMap, ok := res.(map[interface{}]interface{}); !ok {
+	resMap, ok := res.(map[interface{}]interface{})
+
+	if !ok {
 		return nil, fmt.Errorf("Request response object should be a map")
-	} else {
-		if _, ok := resMap["status"]; !ok {
-			resMap["status"] = 200
-		}
-		if _, ok := resMap["headers"]; !ok {
-			resMap["header"] = map[interface{}]interface{}{
-				"Content-Type":           "application/json; charset=utf-8",
-				"X-Content-Type-Options": "nosniff",
-			}
-		}
-		if _, ok := resMap["body"]; !ok {
-			resMap["body"] = map[interface{}]interface{}{}
+	}
+
+	if _, ok := resMap["status"]; !ok {
+		resMap["status"] = 200
+	}
+	if _, ok := resMap["headers"]; !ok {
+		resMap["header"] = map[interface{}]interface{}{
+			"Content-Type":           "application/json; charset=utf-8",
+			"X-Content-Type-Options": "nosniff",
 		}
 	}
+	if _, ok := resMap["body"]; !ok {
+		resMap["body"] = map[interface{}]interface{}{}
+	}
 
 	erp := is["erp"].(*interpreter.ECALRuntimeProvider)
 	node := is["astnode"].(*parser.ASTNode)

+ 4 - 4
graph/util/indexmanager_test.go

@@ -341,11 +341,11 @@ func TestAddRemoveIndexHashEntry(t *testing.T) {
 
 	sm.AccessMap[2] = storage.AccessCacheAndFetchError
 
-	if err := im.addIndexHashEntry("mykey2", "myattr", "testvalue"); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if err := im.addIndexHashEntry("mykey2", "myattr", "testvalue"); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error(err)
 		return
 	}
-	if err := im.removeIndexHashEntry("mykey2", "myattr", "testvalue"); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if err := im.removeIndexHashEntry("mykey2", "myattr", "testvalue"); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error(err)
 		return
 	}
@@ -459,12 +459,12 @@ func TestAddRemoveIndexEntry(t *testing.T) {
 
 	sm.AccessMap[2] = storage.AccessCacheAndFetchError
 
-	if res := im.addIndexEntry("mykey2", "myattr", "myword", []uint64{10, 12, 80}); res.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if res := im.addIndexEntry("mykey2", "myattr", "myword", []uint64{10, 12, 80}); res.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected result:", res)
 		return
 	}
 
-	if res := im.removeIndexEntry("mykey2", "myattr", "myword", []uint64{10, 12, 80}); res.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if res := im.removeIndexEntry("mykey2", "myattr", "myword", []uint64{10, 12, 80}); res.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected result:", res)
 		return
 	}

+ 1 - 1
hash/htree_test.go

@@ -122,7 +122,7 @@ func TestHTree(t *testing.T) {
 
 	sm.AccessMap[1] = storage.AccessCacheAndFetchError
 
-	if _, err := LoadHTree(sm, page.Location()); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := LoadHTree(sm, page.Location()); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected tree load result:", err)
 		return
 	}

+ 8 - 8
hash/htreepage_test.go

@@ -67,11 +67,11 @@ func TestHTreePageFetchExists(t *testing.T) {
 
 	sm.AccessMap[8] = storage.AccessCacheAndFetchError
 
-	if res, err := page.Exists([]byte("testkey4")); res != false || err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if res, err := page.Exists([]byte("testkey4")); res != false || err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected exists result:", res, err)
 		return
 	}
-	if res, _, err := page.Get([]byte("testkey4")); res != nil || err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if res, _, err := page.Get([]byte("testkey4")); res != nil || err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected get result:", res, err)
 		return
 	}
@@ -105,7 +105,7 @@ func TestHTreePageInsert(t *testing.T) {
 
 	sm.AccessMap[1] = storage.AccessUpdateError
 
-	if _, err := page.Put([]byte("testkey1"), "test1"); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Put([]byte("testkey1"), "test1"); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected put result:", err)
 		return
 	}
@@ -120,7 +120,7 @@ func TestHTreePageInsert(t *testing.T) {
 
 	sm.AccessMap[2] = storage.AccessCacheAndFetchError
 
-	if _, err := page.Put([]byte("testkey2"), "test2"); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Put([]byte("testkey2"), "test2"); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected put result:", err)
 		return
 	}
@@ -158,7 +158,7 @@ func TestHTreePageInsert(t *testing.T) {
 
 	sm.AccessMap[1] = storage.AccessUpdateError
 
-	if _, err := page.Put([]byte("testkey9"), "test9"); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Put([]byte("testkey9"), "test9"); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected put result:", err)
 		return
 	}
@@ -369,7 +369,7 @@ func TestHTreePageRemove(t *testing.T) {
 
 	sm.AccessMap[16] = storage.AccessCacheAndFetchError
 
-	if _, err := page.Remove([]byte("testkey1")); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Remove([]byte("testkey1")); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected remove result", res)
 		return
 	}
@@ -378,7 +378,7 @@ func TestHTreePageRemove(t *testing.T) {
 
 	sm.AccessMap[1] = storage.AccessUpdateError
 
-	if _, err := page.Remove([]byte("testkey10")); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Remove([]byte("testkey10")); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected remove result", res)
 		return
 	}
@@ -396,7 +396,7 @@ func TestHTreePageRemove(t *testing.T) {
 
 	sm.AccessMap[1] = storage.AccessUpdateError
 
-	if _, err := page.Remove([]byte("testkey9")); err.(*storage.StorageManagerError).Type != storage.ErrSlotNotFound {
+	if _, err := page.Remove([]byte("testkey9")); err.(*storage.ManagerError).Type != storage.ErrSlotNotFound {
 		t.Error("Unexpected remove result", res)
 		//return
 	}

+ 1 - 1
hash/iterator.go

@@ -105,7 +105,7 @@ func (it *HTreeIterator) nextItem() error {
 
 	if err != nil {
 
-		if smr, ok := err.(*storage.StorageManagerError); ok && smr.Type == storage.ErrSlotNotFound {
+		if smr, ok := err.(*storage.ManagerError); ok && smr.Type == storage.ErrSlotNotFound {
 
 			// Something is wrong - the tree must have changed since the last
 			// nextItem call. Remove the path element and try again.

+ 3 - 3
storage/cacheddiskstoragemanager_test.go

@@ -64,7 +64,7 @@ func TestCachedDiskStorageManager(t *testing.T) {
 
 	// Test getting non-existent entry from cache
 
-	if _, err := cdsm.FetchCached(loc + 1); err.(*StorageManagerError).Type != ErrNotInCache {
+	if _, err := cdsm.FetchCached(loc + 1); err.(*ManagerError).Type != ErrNotInCache {
 		t.Error("Unexpected FetchCached result:", err)
 		return
 	}
@@ -239,7 +239,7 @@ func TestCachedDiskStorageManagerTransactions(t *testing.T) {
 	}
 
 	var ret string
-	if err := cdsm.Fetch(loc, &ret); err.(*StorageManagerError).Type != ErrSlotNotFound ||
+	if err := cdsm.Fetch(loc, &ret); err.(*ManagerError).Type != ErrSlotNotFound ||
 		err.Error() != "Slot not found (ByteDiskStorageFile:storagemanagertest/ctest2 - Location:1 18)" {
 
 		t.Error("Unexpected fetch result:", err)
@@ -287,7 +287,7 @@ func TestCachedDiskStorageManagerTransactions(t *testing.T) {
 		return
 	}
 
-	if err := cdsm.Fetch(loc2, &ret); err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err := cdsm.Fetch(loc2, &ret); err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected fetch result:", err)
 		return
 	}

+ 5 - 5
storage/diskstoragemanager_test.go

@@ -205,7 +205,7 @@ func TestDiskStorageManager1(t *testing.T) {
 	flsp.StorageFile().ReleaseInUse(rflsp)
 
 	_, err = dsm.FetchCached(0)
-	if err.(*StorageManagerError).Type != ErrNotInCache {
+	if err.(*ManagerError).Type != ErrNotInCache {
 		t.Error("Unexpected FetchCached result:", err)
 		return
 	}
@@ -270,7 +270,7 @@ func TestDiskStorageManager2(t *testing.T) {
 	}
 
 	err = dsm.Fetch(util.PackLocation(2, 18), &res)
-	if err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error(err)
 		return
 	}
@@ -278,7 +278,7 @@ func TestDiskStorageManager2(t *testing.T) {
 	dsm.logicalSlotsSf.ReleaseInUse(record)
 
 	err = dsm.Fetch(util.PackLocation(3, 18), &res)
-	if err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error(err)
 		return
 	}
@@ -300,7 +300,7 @@ func TestDiskStorageManager2(t *testing.T) {
 	dsm.logicalSlotsSf.ReleaseInUse(record)
 
 	err = dsm.Update(util.PackLocation(2, 18), "test")
-	if err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error(err)
 		return
 	}
@@ -453,7 +453,7 @@ func TestDiskStorageManager3(t *testing.T) {
 
 	dsm := NewDiskStorageManager(DBDIR+"/test3", false, false, true, true)
 
-	if dsm.Free(util.PackLocation(2, 18)).(*StorageManagerError).Type != ErrSlotNotFound {
+	if dsm.Free(util.PackLocation(2, 18)).(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected free result")
 		return
 	}

+ 5 - 5
storage/globals.go

@@ -31,9 +31,9 @@ var (
 )
 
 /*
-StorageManagerError is a storage manager related error.
+ManagerError is a storage manager related error.
 */
-type StorageManagerError struct {
+type ManagerError struct {
 	Type        error
 	Detail      string
 	Managername string
@@ -42,13 +42,13 @@ type StorageManagerError struct {
 /*
 NewStorageManagerError returns a new StorageManager specific error.
 */
-func NewStorageManagerError(smeType error, smeDetail string, smeManagername string) *StorageManagerError {
-	return &StorageManagerError{smeType, smeDetail, smeManagername}
+func NewStorageManagerError(smeType error, smeDetail string, smeManagername string) *ManagerError {
+	return &ManagerError{smeType, smeDetail, smeManagername}
 }
 
 /*
 Error returns a string representation of the error.
 */
-func (e *StorageManagerError) Error() string {
+func (e *ManagerError) Error() string {
 	return fmt.Sprintf("%s (%s - %s)", e.Type.Error(), e.Managername, e.Detail)
 }

+ 5 - 5
storage/memorystoragemanager_test.go

@@ -28,7 +28,7 @@ func TestMemoryStorageManager(t *testing.T) {
 		return
 	}
 
-	if err := msm.Fetch(5, &ret); err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err := msm.Fetch(5, &ret); err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected fetch result:", err)
 		return
 	}
@@ -77,7 +77,7 @@ func TestMemoryStorageManager(t *testing.T) {
 
 	msm.AccessMap[loc] = AccessNotInCache
 
-	if _, err := msm.FetchCached(loc); err.(*StorageManagerError).Type != ErrNotInCache {
+	if _, err := msm.FetchCached(loc); err.(*ManagerError).Type != ErrNotInCache {
 		t.Error("Unexpected fetchcached result:", err)
 		return
 	}
@@ -98,21 +98,21 @@ func TestMemoryStorageManager(t *testing.T) {
 
 	msm.AccessMap[loc] = AccessFetchError
 
-	if err := msm.Fetch(loc, &ret); err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err := msm.Fetch(loc, &ret); err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected fetch result:", err)
 		return
 	}
 
 	msm.AccessMap[loc] = AccessUpdateError
 
-	if err := msm.Update(loc, ""); err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err := msm.Update(loc, ""); err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected update result:", err)
 		return
 	}
 
 	msm.AccessMap[loc] = AccessFreeError
 
-	if err := msm.Free(loc); err.(*StorageManagerError).Type != ErrSlotNotFound {
+	if err := msm.Free(loc); err.(*ManagerError).Type != ErrSlotNotFound {
 		t.Error("Unexpected free result:", err)
 		return
 	}