Jelajahi Sumber

Add enum hooks to log parseHook jsony errors

Zed 3 tahun lalu
induk
melakukan
da4d6eabdd

+ 2 - 0
src/experimental/parser/unifiedcard.nim

@@ -82,6 +82,8 @@ proc parseUnifiedCard*(json: string): Card =
       component.parseMedia(card, result)
     of buttonGroup:
       discard
+    of unknown:
+      echo "ERROR: Unknown component type: ", json
 
     case component.kind
     of twitterListDetails:

+ 26 - 0
src/experimental/types/unifiedcard.nim

@@ -17,6 +17,7 @@ type
     twitterListDetails
     communityDetails
     mediaWithDetailsHorizontal
+    unknown
 
   Component* = object
     kind*: ComponentType
@@ -77,3 +78,28 @@ converter fromText*(text: Text): string = text.content
 proc renameHook*(v: var HasTypeField; fieldName: var string) =
   if fieldName == "type":
     fieldName = "kind"
+
+proc enumHook*(s: string; v: var ComponentType) =
+  v = case s
+      of "details": details
+      of "media": media
+      of "swipeable_media": swipeableMedia
+      of "button_group": buttonGroup
+      of "app_store_details": appStoreDetails
+      of "twitter_list_details": twitterListDetails
+      of "community_details": communityDetails
+      of "media_with_details_horizontal": mediaWithDetailsHorizontal
+      else: echo "ERROR: Unknown enum value (ComponentType): ", s; unknown
+
+proc enumHook*(s: string; v: var AppType) =
+  v = case s
+      of "android_app": androidApp
+      of "iphone_app": iPhoneApp
+      of "ipad_app": iPadApp
+      else: echo "ERROR: Unknown enum value (AppType): ", s; androidApp
+
+proc enumHook*(s: string; v: var MediaType) =
+  v = case s
+      of "video": video
+      of "photo": photo
+      else: echo "ERROR: Unknown enum value (MediaType): ", s; photo