ZhuLinsen/daily_stock_analysis · error · ValueError

00-daily-analysis.yml is missing required notification env m

Error message

00-daily-analysis.yml is missing required notification env mappings: {missing}

What it means

validate_required_mappings diffs the env block of the '执行股票分析' workflow step against the union of P0/P3/P4/P6 notification env key sets. Any required key absent from the workflow's env raises ValueError listing the missing names. This keeps the generated notification env table and the actual CI configuration in lockstep.

Source

Thrown at scripts/generate_notification_actions_env_table.py:194

    if start == -1 or end == -1 or end < start:
        raise ValueError(
            f"Could not find managed table markers {TABLE_START!r} and {TABLE_END!r}"
        )
    before = markdown[: start + len(TABLE_START)]
    after = markdown[end:]
    return f"{before}\n\n{table}\n\n{after.lstrip()}"


def validate_required_mappings(env: dict[str, str]) -> None:
    required = (
        set(P0_ACTIONS_ENV_KEYS)
        | set(P3_ROUTE_ENV_KEYS)
        | set(P4_NOISE_ACTIONS_ENV_KEYS)
        | set(P6_CHANNEL_ACTIONS_ENV_KEYS)
    )
    missing = sorted(required - set(env))
    if missing:
        raise ValueError(
            "00-daily-analysis.yml is missing required notification env mappings: "
            + ", ".join(missing)
        )


def generate_table() -> str:
    env = load_daily_analysis_env()
    validate_required_mappings(env)
    return render_markdown_table(build_notification_actions_env_rows(env))


def main(argv: list[str] | None = None) -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--write", action="store_true", help="Update docs/notifications.md in place")
    parser.add_argument("--check", action="store_true", help="Fail if docs/notifications.md is stale")
    args = parser.parse_args(argv)

    table = generate_table()

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Add each missing key from the error message to the env block of the '执行股票分析' step in .github/workflows/00-daily-analysis.yml with its proper ${{ secrets.VAR }} / default value.
  2. If a key was intentionally retired, remove it from the corresponding P0/P3/P4/P6 constant in scripts/generate_notification_actions_env_table.py in the same change.
  3. Re-run the generator and verify the docs table reflects the corrected mapping.

Example fix

# before (workflow step env)
env:
  NOTIFICATION_ACTIONS_ENABLED: 'true'
  # NOTIFICATION_DEFAULT_ROUTE removed

# after
env:
  NOTIFICATION_ACTIONS_ENABLED: 'true'
  NOTIFICATION_DEFAULT_ROUTE: ${{ secrets.NOTIFICATION_DEFAULT_ROUTE }}
Defensive patterns

Strategy: validation

Validate before calling

from scripts.generate_notification_actions_env_table import (
    P0_ACTIONS_ENV_KEYS, P3_ROUTE_ENV_KEYS, P4_NOISE_ACTIONS_ENV_KEYS,
    P6_CHANNEL_ACTIONS_ENV_KEYS, load_daily_analysis_env,
)
env = load_daily_analysis_env()
missing = (set(P0_ACTIONS_ENV_KEYS) | set(P3_ROUTE_ENV_KEYS)
           | set(P4_NOISE_ACTIONS_ENV_KEYS) | set(P6_CHANNEL_ACTIONS_ENV_KEYS)) - set(env)
assert not missing, f"workflow env missing: {sorted(missing)}"

Try / catch

try:
    generate_table()
except ValueError as e:
    if "missing required notification env mappings" in str(e):
        add_missing_env_to_workflow(parse_names(str(e)))  # fix workflow, not the script
    else:
        raise

Prevention

When it happens

Trigger: A PR removes or renames a notification-related env var (e.g. a P0_ACTIONS_ENV_KEYS entry like a channel/route variable) from the workflow step's env block; new keys added to the P*_ENV_KEYS constants in the script without adding them to the workflow; YAML typo in an env var name.

Common situations: Refactoring notification config: someone cleans 'unused' env vars out of 00-daily-analysis.yml not knowing the docs generator requires them; renaming env keys across the repo but missing the workflow; adding a new notification channel constant in the script first.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/cb4255d04a6019fd. Report an issue: GitHub.