Skip to content

Commit 7ec6504

Browse files
committed
feat: Warn when option could not be set because the option does not exist
1 parent e7a98b5 commit 7ec6504

File tree

1 file changed

+8
-3
lines changed
  • src/commonMain/kotlin/app/revanced/library

1 file changed

+8
-3
lines changed

src/commonMain/kotlin/app/revanced/library/Options.kt

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ private val logger = Logger.getLogger("Options")
1919
* @param options The options to set. The key is the patch name and the value is a map of option keys to option values.
2020
*/
2121
fun Set<Patch<*>>.setOptions(options: PatchesOptions) = filter { it.name != null }.forEach { patch ->
22-
val patchOptions = options[patch.name] ?: return@forEach
22+
options[patch.name]?.forEach setOption@{ (optionKey, optionValue) ->
23+
if (optionKey !in patch.options) {
24+
return@setOption logger.warning(
25+
"Could not set option for the \"${patch.name}\" patch because " +
26+
"option with key \"${optionKey}\" does not exist",
27+
)
28+
}
2329

24-
patch.options.forEach option@{ option ->
2530
try {
26-
patch.options[option.key] = patchOptions[option.key] ?: return@option
31+
patch.options[optionKey] = optionValue
2732
} catch (e: OptionException) {
2833
logger.warning("Could not set option value for the \"${patch.name}\" patch: ${e.message}")
2934
}

0 commit comments

Comments
 (0)