Add enum hooks to log parseHook jsony errors

このコミットが含まれているのは:
Zed 2022-11-27 17:24:29 +01:00
コミット da4d6eabdd
2個のファイルの変更28行の追加0行の削除

ファイルの表示

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

ファイルの表示

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