Skip to content

Commit

Permalink
fix: always return PatchResultSuccess on patch success
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas authored and oSumAtrIX committed Jun 5, 2022
1 parent 5b28523 commit 996c4ac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/kotlin/app/revanced/patcher/Patcher.kt
Expand Up @@ -2,7 +2,7 @@ package app.revanced.patcher

import app.revanced.patcher.cache.Cache
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.signature.resolver.SignatureResolver
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.util.ListBackedSet
Expand Down Expand Up @@ -99,15 +99,18 @@ class Patcher(
/**
* Apply patches loaded into the patcher.
* @param stopOnError If true, the patches will stop on the first error.
* @return A map of results. If the patch was successfully applied,
* PatchResultSuccess will always be returned in the wrapping Result object.
* If the patch failed to apply, an Exception will always be returned in the wrapping Result object.
*/
fun applyPatches(stopOnError: Boolean = false, callback: (String) -> Unit = {}): Map<String, Result<PatchResult>> {
fun applyPatches(stopOnError: Boolean = false, callback: (String) -> Unit = {}): Map<String, Result<PatchResultSuccess>> {
return buildMap {
for (patch in patches) {
callback(patch.patchName)
val result: Result<PatchResult> = try {
val result: Result<PatchResultSuccess> = try {
val pr = patch.execute(cache)
if (pr.isSuccess()) {
Result.success(pr)
Result.success(pr.success()!!)
} else {
Result.failure(Exception(pr.error()?.errorMessage() ?: "Unknown error"))
}
Expand Down

0 comments on commit 996c4ac

Please sign in to comment.