Browse Source

query node - mappings logging II

ondratra 4 years ago
parent
commit
43b219504d

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

@@ -23,7 +23,7 @@ import {
 
 const currentNetwork = Network.BABYLON
 
-export function inconsistentState(extraInfo?: string, data?: unknown): never {
+export function inconsistentState(extraInfo: string, data?: unknown): never {
   const errorMessage = 'Inconsistent state: ' + extraInfo
 
   // log error
@@ -84,11 +84,11 @@ Logger will not be needed in the future when Hydra v3 will be released.
 
 class Logger {
 
-  info(message: string, data: unknown) {
+  info(message: string, data?: unknown) {
     console.log(message, data)
   }
 
-  error(message: string, data: unknown) {
+  error(message: string, data?: unknown) {
     console.error(message, data)
   }
 }

+ 6 - 7
query-node/mappings/src/content/channel.ts

@@ -63,10 +63,9 @@ export async function content_ChannelUpdated(
 
   // ensure channel exists
   if (!channel) {
-    return inconsistentState()
+    return inconsistentState('Non-existing channel update requested', channelId)
   }
 
-
   // prepare changed metadata
   const newMetadata = channelUpdateParameters.new_meta.isSome && channelUpdateParameters.new_meta.unwrapOr(null)
 
@@ -131,7 +130,7 @@ export async function content_ChannelCensored(
 
   // ensure channel exists
   if (!channel) {
-    return inconsistentState()
+    return inconsistentState('Non-existing channel censoring requested', channelId)
   }
 
   // update channel
@@ -157,7 +156,7 @@ export async function content_ChannelUncensored(
 
   // ensure channel exists
   if (!channel) {
-    return inconsistentState()
+    return inconsistentState('Non-existing channel uncensoring requested', channelId)
   }
 
   // update channel
@@ -217,7 +216,7 @@ export async function content_ChannelCategoryUpdated(
 
   // ensure channel exists
   if (!channelCategory) {
-    return inconsistentState()
+    return inconsistentState('Non-existing channel category update requested', channelCategoryId)
   }
 
   // read metadata
@@ -254,7 +253,7 @@ export async function content_ChannelCategoryDeleted(
 
   // ensure channel category exists
   if (!channelCategory) {
-    return inconsistentState()
+    return inconsistentState('Non-existing channel category deletion requested', channelCategoryId)
   }
 
   // delete channel category
@@ -272,7 +271,7 @@ function handleChannelRewardAccountChange(
 ) {
   // new different reward account set?
   if (reward_account.isSome) {
-    channel.rewardAccount = reward_account.unwrap().toString()
+    channel.rewardAccount = reward_account.unwrap().toString() // TODO: get rid of unwrap
     return
   }
 

+ 4 - 4
query-node/mappings/src/content/curatorGroup.ts

@@ -42,7 +42,7 @@ export async function content_CuratorGroupStatusSet(
 
   // ensure curator group exists
   if (!curatorGroup) {
-    return inconsistentState()
+    return inconsistentState('Non-existing curator group status set requested', curatorGroupId)
   }
 
   // update curator group
@@ -67,7 +67,7 @@ export async function content_CuratorAdded(
 
   // ensure curator group exists
   if (!curatorGroup) {
-    return inconsistentState()
+    return inconsistentState('Curator add to non-existing curator group requested', curatorGroupId)
   }
 
   // update curator group
@@ -92,14 +92,14 @@ export async function content_CuratorRemoved(
 
   // ensure curator group exists
   if (!curatorGroup) {
-    return inconsistentState()
+    return inconsistentState('Non-existing curator group removal requested', curatorGroupId)
   }
 
   const curatorIndex = curatorGroup.curatorIds.indexOf(curatorId)
 
   // ensure curator group exists
   if (curatorIndex < 0) {
-    return inconsistentState()
+    return inconsistentState('Non-associated curator removal from curator group requested', curatorId)
   }
 
   // update curator group

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

@@ -195,7 +195,7 @@ async function extractAsset(
   }
 
   if (assetIndex > assets.length) {
-    return inconsistentState()
+    return inconsistentState(`Non-existing asset extraction requested`, {assetsProvided: assets.length, assetIndex})
   }
 
   return convertAsset(assets[assetIndex], db, event)
@@ -207,7 +207,7 @@ async function extractVideoSize(assets: NewAsset[], assetIndex: number | undefin
   }
 
   if (assetIndex > assets.length) {
-    return inconsistentState()
+    return inconsistentState(`Non-existing asset video size extraction requested`, {assetsProvided: assets.length, assetIndex})
   }
 
   const rawAsset = assets[assetIndex]
@@ -229,7 +229,7 @@ async function prepareLanguage(languageIso: string, db: DatabaseManager): Promis
   const isValidIso = ISO6391.validate(languageIso);
 
   if (!isValidIso) {
-    return inconsistentState()
+    return inconsistentState(`Invalid language ISO-639-1 provided`, languageIso)
   }
 
   const language = await db.get(Language, { where: { iso: languageIso }})
@@ -271,7 +271,7 @@ async function prepareVideoCategory(categoryId: number, db: DatabaseManager): Pr
   const category = await db.get(VideoCategory, { where: { id: categoryId }})
 
   if (!category) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video category association with video requested', categoryId)
   }
 
   return category

+ 10 - 7
query-node/mappings/src/content/video.ts

@@ -66,7 +66,7 @@ export async function content_VideoCategoryUpdated(
 
   // ensure video category exists
   if (!videoCategory) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video category update requested', videoCategoryId)
   }
 
   // read metadata
@@ -103,7 +103,7 @@ export async function content_VideoCategoryDeleted(
 
   // ensure video category exists
   if (!videoCategory) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video category deletion requested', videoCategoryId)
   }
 
   // remove video category
@@ -161,7 +161,7 @@ export async function content_VideoUpdated(
 
   // ensure video exists
   if (!video) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video update requested', videoId)
   }
 
   // prepare changed metadata
@@ -213,7 +213,7 @@ export async function content_VideoDeleted(
 
   // ensure video exists
   if (!video) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video deletion requested', videoId)
   }
 
   // remove video
@@ -236,7 +236,7 @@ export async function content_VideoCensored(
 
   // ensure video exists
   if (!video) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video censoring requested', videoId)
   }
 
   // update video
@@ -262,7 +262,7 @@ export async function content_VideoUncensored(
 
   // ensure video exists
   if (!video) {
-    return inconsistentState()
+    return inconsistentState('Non-existing video uncensoring requested', videoId)
   }
 
   // update video
@@ -310,6 +310,9 @@ export async function content_FeaturedVideosSet(
 
   // escape if no featured video needs to be added
   if (!toAdd) {
+    // emit log event
+    logger.info('Featured videos unchanged')
+
     return
   }
 
@@ -317,7 +320,7 @@ export async function content_FeaturedVideosSet(
   const videosToAdd = await db.getMany(Video, { where: { id: [toAdd] } })
 
   if (videosToAdd.length != toAdd.length) {
-    return inconsistentState()
+    return inconsistentState('At least one non-existing video featuring requested', toAdd)
   }
 
   // mark previously not-featured videos as featured

+ 1 - 1
query-node/mappings/src/membership.ts

@@ -22,7 +22,7 @@ async function getMemberById(db: DatabaseManager, id: MemberId): Promise<Members
 
   // ensure member exists
   if (!member) {
-    return inconsistentState(`Member(${id}) not found`)
+    return inconsistentState(`Operation on non-existing member requested`, id)
   }
   return member
 }

+ 2 - 2
query-node/mappings/src/storage.ts

@@ -61,7 +61,7 @@ export async function ContentAccepted(db: DatabaseManager, event: SubstrateEvent
 
   // ensure object exists
   if (!assetDataObject) {
-    return inconsistentState()
+    return inconsistentState('Non-existing content acceptation requested', contentId)
   }
 
   // update object
@@ -83,7 +83,7 @@ export async function ContentRejected(db: DatabaseManager, event: SubstrateEvent
 
   // ensure object exists
   if (!assetDataObject) {
-    return inconsistentState()
+    return inconsistentState('Non-existing content rejection requested', contentId)
   }
 
   // update object