Skip to content

Conversation

@tnswo561412
Copy link

@tnswo561412 tnswo561412 commented Dec 14, 2025

Summary

  • Validate and download patch bundle before saving to database
  • Show user-friendly error messages instead of raw JSON payloads
  • Prevent invalid URLs from being saved as "Unnamed" patch sources

Test plan

  • Add an invalid patch source URL (e.g., https://github.com/non_existent_user/repo)
  • Verify that the source is NOT added to the list
  • Verify that a user-friendly error message is shown
  • Add a valid patch source URL and verify it works correctly

Closes #2792

@tnswo561412
Copy link
Author

I have resolved the merge conflicts and fixed the build errors. (Note: The remaining CI failure regarding the 'GPG key' seems expected for a fork.) Could you please review the changes again?

@oSumAtrIX
Copy link
Member

Can you link the respective issue this RP closes?

@tnswo561412
Copy link
Author

Done. I have added the issue number in the PR description/body.

@oSumAtrIX oSumAtrIX linked an issue Dec 15, 2025 that may be closed by this pull request
4 tasks
Comment on lines +372 to +373
// Reload to update metadata
reload()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary now?

Comment on lines +314 to +329
// Validate URL format first
val source = try {
SourceInfo.from(url)
} catch (e: Exception) {
throw InvalidBundleSourceException(
app.getString(R.string.source_invalid_url),
e
)
}

// Ensure it's a remote source
if (source !is SourceInfo.Remote) {
throw InvalidBundleSourceException(
app.getString(R.string.source_invalid_url)
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to the caller and make the function accept a SourceInfo.Remote instead.

Comment on lines +357 to +364
// Clean up any partial downloads
dir.deleteRecursively()
if (e is CancellationException) throw e
Log.e(tag, "Failed to validate patch source: $url", e)
throw InvalidBundleSourceException(
app.getString(R.string.source_add_fail, e.simpleMessage()),
e
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch block definitely needs to be tested. dispatchAction does not block and exceptions thrown in it will not be propagated to the caller (they have their own handler).

versionHash = with(src) { downloadLatest() }
} catch (e: Exception) {
// Clean up any partial downloads
dir.deleteRecursively()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this cleanup logic is sufficient. The app process might crash or be suspended during the download if it takes a long time, and that would leave those files on disk. This wasn't a problem before, since the user could just delete the bad bundle or reattempt the download.

suspend fun createRemote(url: String, autoUpdate: Boolean) {
// Validate URL format first
val source = try {
SourceInfo.from(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create a remote bundle directly? Since the input has to be a url anyway and isn't supposed to create other bundle types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Entering an invalid patches source url shows a confusing error message

4 participants