agentsclimarketplace

Missing env var

Skill viditkbhatnagar/immunize/src/immunize/patterns/missing-env-var

Use when reading configuration from os.environ to check for missing values and raise a specific ConfigError instead of letting a raw KeyError escape.From its SKILL.md

Install
npx -y skills add viditkbhatnagar/immunize --skill missing-env-var

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • reads credentialsReads from 2 credential sources: `APP_API_KEY` and 1 more.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

1.8 KB, 402 tokens by cl100k_base, as published. Nobody here has run it

missing-env-var

os.environ[...] is dict-style indexing. Missing keys raise KeyError with no context — the traceback shows an indexing line, not a message about which variable was expected or why the program needs it. In production logs, this reads as a mystery crash:

KeyError: 'APP_API_KEY'
  File "app/config.py", line 12, in get_api_key
    return os.environ["APP_API_KEY"]

Example

Wrong — opaque KeyError; caller has no idea what to fix:

import os

def get_api_key() -> str:
    return os.environ["APP_API_KEY"]

Right — explicit check, specific error, actionable message:

import os

class ConfigError(Exception):
    pass

def get_api_key() -> str:
    value = os.environ.get("APP_API_KEY")
    if not value:
        raise ConfigError(
            "APP_API_KEY is not set. Export it before running."
        )
    return value

Prefer failing at startup

Read configuration once at process boot, not on every request. A missing key should surface before the first user hits the path:

REQUIRED = ("APP_API_KEY", "APP_DB_URL")

def load_config() -> dict[str, str]:
    missing = [k for k in REQUIRED if not os.environ.get(k)]
    if missing:
        raise ConfigError(f"missing env vars: {', '.join(missing)}")
    return {k: os.environ[k] for k in REQUIRED}

This turns a 500 during a user request into a crash at boot — loud, visible, and immediately fixable.

Treat empty strings as missing

.get() returns the empty string if the var is exported but empty. Use if not value: rather than if value is None: — an empty string is almost never what you want for an API key or URL.

What ships with it: 5 files

5.6 KB alongside SKILL.md, 3 of them executable

fixtures/

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.