Skip to content

Commit 41bba7c

Browse files
committed
Revert "refactor: Enhance error handling in contest filters to log non-fatal warnings for missing categories and unrecognized wikis"
This reverts commit 966e69d.
1 parent e6305bf commit 41bba7c

File tree

2 files changed

+12
-54
lines changed

2 files changed

+12
-54
lines changed

ukbot/contest.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -224,31 +224,14 @@ def extract_rules(self, txt, catignore_page=''):
224224
try:
225225
filter_inst = filter_tpl.make(self)
226226
except RuntimeError as exp:
227-
# Only abort for truly fatal errors (like missing required arguments)
228-
fatal_errors = [
229-
'Too few arguments',
230-
'No category values given',
231-
'No byte limit',
232-
'No "%s" parameter given',
233-
'Could not parse the catignore page',
234-
]
235-
msg = str(exp)
236-
if any(fe in msg for fe in fatal_errors):
237-
raise InvalidContestPage(
238-
_('Could not parse {{tlx|%(template)s|%(firstarg)s}} template: %(err)s')
239-
% {
240-
'template': filter_template_config['name'],
241-
'firstarg': filter_tpl.anon_params[1],
242-
'err': msg
243-
}
244-
)
245-
# Otherwise, treat as warning and continue
246-
logger.warning('Non-fatal filter error: %s', msg)
247-
try:
248-
self.sites.homesite.errors.append(_('Warning: %(msg)s') % {'msg': msg})
249-
except Exception as e:
250-
logger.warning('Could not attach warning to homesite: %s', e)
251-
continue
227+
raise InvalidContestPage(
228+
_('Could not parse {{tlx|%(template)s|%(firstarg)s}} template: %(err)s')
229+
% {
230+
'template': filter_template_config['name'],
231+
'firstarg': filter_tpl.anon_params[1],
232+
'err': str(exp)
233+
}
234+
)
252235

253236
nfilters += 1
254237
if op == 'OR':

ukbot/filters.py

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -237,28 +237,13 @@ def make(cls, tpl: 'FilterTemplate', **kwargs):
237237
if len(tpl.anon_params) < 3:
238238
raise RuntimeError(_('No category values given!'))
239239

240-
# Build category list, catching missing categories as warnings
241-
categories = []
242-
for cat_name in tpl.anon_params[2:]:
243-
if cat_name.strip() == '':
244-
continue
245-
try:
246-
cat_page = tpl.sites.resolve_page(cat_name, 14, True)
247-
categories.append(cat_page)
248-
except InvalidContestPage as e:
249-
logger.warning('Category does not exist: %s', cat_name)
250-
try:
251-
self_site = tpl.sites.homesite
252-
self_site.errors.append(_('Warning: Category does not exist: %(cat)s') % {'cat': cat_name})
253-
except Exception as ex:
254-
logger.warning('Could not attach warning to homesite: %s', ex)
255-
# Do not abort, just skip this category
256-
continue
257-
258240
params = {
259241
'sites': tpl.sites,
260242
'ignore': cls.get_ignore_list(tpl, kwargs.get('cfg', {}).get('ignore_page')),
261-
'categories': categories,
243+
'categories': [
244+
tpl.sites.resolve_page(cat_name, 14, True)
245+
for cat_name in tpl.anon_params[2:] if cat_name.strip() != ''
246+
],
262247
}
263248

264249
if tpl.has_param('ignore'):
@@ -270,16 +255,6 @@ def make(cls, tpl: 'FilterTemplate', **kwargs):
270255
if tpl.has_param('maxdepth'):
271256
params['maxdepth'] = int(tpl.get_param('maxdepth'))
272257

273-
# If a category is on an unrecognized wiki, warn but do not abort
274-
for cat in params['categories']:
275-
if not hasattr(cat, 'site') or cat.site.key not in tpl.sites.keys():
276-
logger.warning('Category on unrecognized wiki: %s', getattr(cat, 'name', str(cat)))
277-
try:
278-
self_site = tpl.sites.homesite
279-
self_site.errors.append(_('Warning: Category on unrecognized wiki: %(cat)s') % {'cat': getattr(cat, 'name', str(cat))})
280-
except Exception as e:
281-
logger.warning('Could not attach warning to homesite: %s', e)
282-
283258
return cls(**params)
284259

285260
def __init__(self, sites: 'SiteManager', categories: List[Union['Page', WildcardPage]], maxdepth: int = 5,

0 commit comments

Comments
 (0)