promptdojo_

pathlib — the file API AI should reach for first — step 7 of 9

AI wrote a function that reads a config file and falls back to a default if the file is missing. Trouble is, the function calls read_text first and then has nothing to catch the FileNotFoundError. The script crashes when the path doesn't exist.

Add an if path.exists(): guard so the function returns "default config" when the file is missing and the file's contents when it exists.

The break is on line 4 — but read the whole snippet first.

full-screen editor opens — close anytime to keep reading.