# Error handling style rules (YAML constraint example) rules: - name: explicit_exceptions rule: "Raise explicit exceptions (ValueError, ProviderError) for known error conditions rather than returning magic values." examples: - good: | if not isinstance(text, str): raise ProviderError('text must be a string') - bad: | if not isinstance(text, str): return [] - name: avoid_broad_except rule: "Avoid 'except Exception:' that swallows errors. If broad except is used for best-effort, log the exception with logger.exception and re-raise or convert." examples: - bad: | try: do_work() except Exception: return [] - remediation: | try: do_work() except SpecificError as exc: logger.warning('Handled error: %s', exc) raise - name: logging_over_print rule: "Prefer logger.* over print() for messages and errors." examples: - bad: "print('Error fetching motions from API: %s' % e)" - good: "logger.exception('Error fetching motions from API')" enforcement_examples: - "Add a static code check to flag 'print(' in modules (except in simple scripts) and 'except Exception:' usages without logger.exception."