mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
AutoMod: error if both "type: any" rules fail
If a rule definition specifies "type: any" (or does not specify type at all), we try to create two separate rules for both comments and submissions using the rule definition. If a particular type fails to create, we just throw it away silently, considering this to mean that the rule definition was actually only intended to apply to one type or the other. However, if there is an error in the rule that results in *both* the submission and comment attempts being thrown away, this means that the entire rule will just end up being silently ignored. This adds an error for that case, so that the user knows they need to fix their definition.
This commit is contained in:
@@ -235,16 +235,21 @@ class Ruleset(object):
|
||||
type = values.get("type", "any")
|
||||
if type == "any":
|
||||
# try to create two Rules for comments and links
|
||||
rule = None
|
||||
for type_value in ("comment", "submission"):
|
||||
values["type"] = type_value
|
||||
try:
|
||||
rule = Rule(values)
|
||||
except AutoModeratorRuleTypeError:
|
||||
except AutoModeratorRuleTypeError as type_error:
|
||||
continue
|
||||
|
||||
# only keep the rule if it had any checks
|
||||
if rule.has_any_checks(targets_only=True):
|
||||
self.rules.append(Rule(values))
|
||||
|
||||
# if both types hit exceptions we should actually error
|
||||
if not rule:
|
||||
raise type_error
|
||||
else:
|
||||
self.rules.append(Rule(values))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user