Add enum hooks to log parseHook jsony errors

This commit is contained in:
Zed 2022-11-27 17:24:29 +01:00
parent 6a7e56b613
commit da4d6eabdd
2 changed files with 28 additions and 0 deletions

View file

@ -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:

View file

@ -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