A pipeline config has multiple required keys — source, destination, label. Why return all missing keys at once instead of raising on the first one?
Because the user wants to fix everything in one pass? If I raise on the first, they re-run, fail on the second, re-run, fail on the third — three cycles for one config fix.
Exactly. Collect every missing key in one list and return them together. The caller sees the whole picture and fixes the config once:
required = ["source", "destination", "label"]
missing = [key for key in required if key not in config]If missing is empty, validation passed — return an empty list as a success sentinel?
Yes. Empty list means 'nothing missing'. Any non-empty list means 'these keys need to be added'. The caller checks if not errors to proceed:
def validate_pipeline_config(config: dict) -> list:
required = ["source", "destination", "label"]
missing = [key for key in required if key not in config]
if missing:
print(f"Config validation failed: missing {missing}")
else:
print("Config valid; ready to run pipeline")
return missingWhat if a required key is present but its value is None or an empty string?
Change the check from key not in config to not config.get(key). That catches None, empty string, empty list, zero, and missing keys in one expression. Which check to use depends on whether you consider falsy values invalid in your config.
So before any pipeline touches Gmail or Tasks, it validates its whole config and either fails fast with every error or passes cleanly?
Fail fast, fail complete. Every pipeline in Week 4 starts with this guard — no API call runs until the config passes.
TL;DR: Collect every missing key in one list, return it as the error report. Empty list means valid.
[key for key in required if key not in config] collects all missing keys in one passif not errors to proceed| Check | Flags |
|---|---|
key not in config | truly missing keys |
not config.get(key) | missing + None + empty string + zero |
A pipeline config has multiple required keys — source, destination, label. Why return all missing keys at once instead of raising on the first one?
Because the user wants to fix everything in one pass? If I raise on the first, they re-run, fail on the second, re-run, fail on the third — three cycles for one config fix.
Exactly. Collect every missing key in one list and return them together. The caller sees the whole picture and fixes the config once:
required = ["source", "destination", "label"]
missing = [key for key in required if key not in config]If missing is empty, validation passed — return an empty list as a success sentinel?
Yes. Empty list means 'nothing missing'. Any non-empty list means 'these keys need to be added'. The caller checks if not errors to proceed:
def validate_pipeline_config(config: dict) -> list:
required = ["source", "destination", "label"]
missing = [key for key in required if key not in config]
if missing:
print(f"Config validation failed: missing {missing}")
else:
print("Config valid; ready to run pipeline")
return missingWhat if a required key is present but its value is None or an empty string?
Change the check from key not in config to not config.get(key). That catches None, empty string, empty list, zero, and missing keys in one expression. Which check to use depends on whether you consider falsy values invalid in your config.
So before any pipeline touches Gmail or Tasks, it validates its whole config and either fails fast with every error or passes cleanly?
Fail fast, fail complete. Every pipeline in Week 4 starts with this guard — no API call runs until the config passes.
TL;DR: Collect every missing key in one list, return it as the error report. Empty list means valid.
[key for key in required if key not in config] collects all missing keys in one passif not errors to proceed| Check | Flags |
|---|---|
key not in config | truly missing keys |
not config.get(key) | missing + None + empty string + zero |
Create a free account to get started. Paid plans unlock all tracks.