Skip to content

Commit

Permalink
less fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Mar 5, 2024
1 parent c4b59b7 commit 2875286
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):
assert is_testcase(yaml)
assert config.COMPILED_FILE_NAME_REGEX.fullmatch(name + '.in')

# if False rule will be skipped during generation
self.ok = True

if name.endswith('.in'):
error(f'Testcase names should not end with \'.in\': {parent.path / name}')
name = name[:-3]
Expand Down Expand Up @@ -434,7 +437,11 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):

if yaml is None:
intarget = self.path.parent / (self.path.name + '.in')
fatal(f'Empty yaml key (Testcases must be generated not mentioned): {intarget}')
error(
f'Empty yaml key (Testcases must be generated not mentioned): {intarget}. Skipping.'
)
self.ok = False
return
else:
check_type('testcase', yaml, [str, dict])
if isinstance(yaml, str):
Expand All @@ -455,7 +462,9 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):
if 'generate' in yaml:
check_type('generate', yaml['generate'], str)
if len(yaml['generate']) == 0:
fatal(f'`generate` must not be empty')
error(f'`generate` must not be empty. Skipping.')
self.ok = False
return

self.generator = GeneratorInvocation(problem, yaml['generate'])

Expand Down Expand Up @@ -504,7 +513,9 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):
# Warn/Error for unknown keys.
for key in yaml:
if key in RESERVED_TESTCASE_KEYS:
fatal('Testcase must not contain reserved key {key}.')
error('Testcase must not contain reserved key {key}. Skipping.')
self.ok = False
return
if key not in KNOWN_TESTCASE_KEYS:
if config.args.action == 'generate':
log(f'Unknown testcase level key: {key} in {self.path}')
Expand All @@ -526,9 +537,11 @@ def __init__(self, problem, generator_config, key, name: str, yaml, parent):
if self.hash in generator_config.rules_cache:
# This is fatal to prevent crashes later on when running generators in parallel.
# https://github.com/RagnarGrootKoerkamp/BAPCtools/issues/310
fatal(
f'Found identical input at {generator_config.rules_cache[self.hash]} and {self.path}'
error(
f'Found identical input at {generator_config.rules_cache[self.hash]} and {self.path}. Skipping.'
)
self.ok = False
return
generator_config.rules_cache[self.hash] = self.path

def generate(t, problem, generator_config, parent_bar):
Expand All @@ -537,6 +550,9 @@ def generate(t, problem, generator_config, parent_bar):
t.generate_success = False

# Some early checks.
if not t.ok:
bar.done(False, f'Invalid yaml entry.')
return
if t.generator and t.generator.program is None:
bar.done(False, f'Generator didn\'t build.')
return
Expand Down

0 comments on commit 2875286

Please sign in to comment.