Skip to content

Commit

Permalink
Fixed a crash in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Jun 6, 2024
1 parent 87bd74d commit 4bfe0f9
Showing 1 changed file with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,51 +398,58 @@ class FeedArticleViewModel(
textToDisplay: TextToDisplay,
): LinearArticle {
// Can't use view state here because this function is called before view state is updated
val htmlLinearizer = HtmlLinearizer()
return when (textToDisplay) {
TextToDisplay.DEFAULT -> {
if (blobFile(article.id, filePathProvider.articleDir).isFile) {
try {
blobInputStream(article.id, filePathProvider.articleDir).use {
htmlLinearizer.linearize(
inputStream = it,
baseUrl = article.feedUrl ?: "",
)
return try {
val htmlLinearizer = HtmlLinearizer()
when (textToDisplay) {
TextToDisplay.DEFAULT -> {
if (blobFile(article.id, filePathProvider.articleDir).isFile) {
try {
blobInputStream(article.id, filePathProvider.articleDir).use {
htmlLinearizer.linearize(
inputStream = it,
baseUrl = article.feedUrl ?: "",
)
}
} catch (e: Exception) {
// EOFException is possible
Log.e(LOG_TAG, "Could not open blob", e)
LinearArticle(elements = emptyList())
}
} catch (e: Exception) {
// EOFException is possible
Log.e(LOG_TAG, "Could not open blob", e)
} else {
Log.e(LOG_TAG, "No default file to parse")
setTextToDisplayFor(article.id, TextToDisplay.FAILED_NOT_HTML)
LinearArticle(elements = emptyList())
}
} else {
Log.e(LOG_TAG, "No default file to parse")
setTextToDisplayFor(article.id, TextToDisplay.FAILED_NOT_HTML)
LinearArticle(elements = emptyList())
}
}
TextToDisplay.FULLTEXT -> {
if (blobFullFile(article.id, filePathProvider.fullArticleDir).isFile) {
try {
blobFullInputStream(article.id, filePathProvider.fullArticleDir).use {
htmlLinearizer.linearize(
inputStream = it,
baseUrl = article.feedUrl ?: "",
)

TextToDisplay.FULLTEXT -> {
if (blobFullFile(article.id, filePathProvider.fullArticleDir).isFile) {
try {
blobFullInputStream(article.id, filePathProvider.fullArticleDir).use {
htmlLinearizer.linearize(
inputStream = it,
baseUrl = article.feedUrl ?: "",
)
}
} catch (e: Exception) {
// EOFException is possible
Log.e(LOG_TAG, "Could not open blob", e)
LinearArticle(elements = emptyList())
}
} catch (e: Exception) {
// EOFException is possible
Log.e(LOG_TAG, "Could not open blob", e)
} else {
Log.e(LOG_TAG, "No fulltext file to parse")
setTextToDisplayFor(article.id, TextToDisplay.FAILED_NOT_HTML)
LinearArticle(elements = emptyList())
}
} else {
Log.e(LOG_TAG, "No fulltext file to parse")
setTextToDisplayFor(article.id, TextToDisplay.FAILED_NOT_HTML)
}

else -> {
LinearArticle(elements = emptyList())
}
}
else -> {
LinearArticle(elements = emptyList())
}
} catch (t: Throwable) {
Log.e(LOG_TAG, "Error parsing article", t)
LinearArticle(elements = emptyList())
}
}

Expand Down

0 comments on commit 4bfe0f9

Please sign in to comment.