mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-14 17:15:09 +00:00
Handle parse errors gracefully on timeline items
Prior to this commit, if even a single item fails to parse Invidious will throw out an error. This means that even if everything else on a page can be parsed and rendered without issues, the single problematic item will cause the entire page to be unusable. This commit gracefully handles parse errors by catching and then replacing the problematic item with a new "timeline error" object that represents the parse error. This will allow the rest of the page to be rendered and an error card that will replace the location of the problematic item.
This commit is contained in:
@@ -291,6 +291,24 @@ struct SearchHashtag
|
||||
end
|
||||
end
|
||||
|
||||
# A `ProblematicTimelineItem` is a `SearchItem` created by Invidious that
|
||||
# represents an item that caused an exception during parsing.
|
||||
#
|
||||
# This is not a parsed object from YouTube but rather an Invidious-only type
|
||||
# created to gracefully communicate parse errors without throwing away
|
||||
# the rest of the (hopefully) successfully parsed item on a page.
|
||||
struct ProblematicTimelineItem
|
||||
property parse_exception : Exception
|
||||
|
||||
def initialize(@parse_exception); end
|
||||
|
||||
def to_json(locale : String?, json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "type", "parse-error"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Category
|
||||
include DB::Serializable
|
||||
|
||||
@@ -333,4 +351,4 @@ struct Continuation
|
||||
end
|
||||
end
|
||||
|
||||
alias SearchItem = SearchVideo | SearchChannel | SearchPlaylist | SearchHashtag | Category
|
||||
alias SearchItem = SearchVideo | SearchChannel | SearchPlaylist | SearchHashtag | Category | ProblematicTimelineItem
|
||||
|
||||
Reference in New Issue
Block a user