Ver Fonte

query node - error throws on inconsistent states

ondratra há 3 anos atrás
pai
commit
e290f47a90

+ 3 - 1
query-node/mappings/src/common.ts

@@ -21,11 +21,13 @@ const currentNetwork = Network.BABYLON
 /*
   Reports that insurmountable inconsistent state has been encountered and throws an exception.
 */
-export function inconsistentState(extraInfo: string, data?: unknown): void {
+export function inconsistentState(extraInfo: string, data?: unknown): never {
   const errorMessage = 'Inconsistent state: ' + extraInfo
 
   // log error
   logger.error(errorMessage, data)
+
+  throw errorMessage
 }
 
 /*

+ 2 - 4
query-node/mappings/src/content/utils.ts

@@ -369,8 +369,7 @@ export async function convertContentActorToChannelOwner(db: DatabaseManager, con
 
     // ensure member exists
     if (!member) {
-      inconsistentState(`Actor is non-existing member`, memberId)
-      return {} // this will keep fields unchanged
+      return inconsistentState(`Actor is non-existing member`, memberId)
     }
 
     return {
@@ -385,8 +384,7 @@ export async function convertContentActorToChannelOwner(db: DatabaseManager, con
 
     // ensure curator group exists
     if (!curatorGroup) {
-      inconsistentState('Actor is non-existing curator group', curatorGroupId)
-      return {} // this will keep fields unchanged
+      return inconsistentState('Actor is non-existing curator group', curatorGroupId)
     }
 
     return {

+ 2 - 2
query-node/mappings/src/content/video.ts

@@ -182,7 +182,7 @@ export async function content_VideoCreated(
 
   // ensure channel exists
   if (!channel) {
-    inconsistentState('Trying to add video to non-existing channel', channelId)
+    return inconsistentState('Trying to add video to non-existing channel', channelId)
   }
 
   // prepare video media metadata (if any)
@@ -385,7 +385,7 @@ export async function content_FeaturedVideosSet(
   } as FindConditions<Video> })
 
   if (videosToAdd.length != toAdd.length) {
-    inconsistentState('At least one non-existing video featuring requested', toAdd)
+    return inconsistentState('At least one non-existing video featuring requested', toAdd)
   }
 
   // mark previously not-featured videos as featured