Bug Fix

The Missing Key Crash

The Missing Key Crash

Bug Report

A function tries to read a nested 'timeout' value from a config dict. If the config is missing the 'network' key entirely, the app crashes with a KeyError.

DictionariesKeyErrorDefaults
Fix the Bug: The Missing Key Crash

Directly indexing nested dictionaries with square brackets assumes every intermediate key exists. If any key along the path is missing, Python raises a KeyError. Using .get() with default fallback values at each level avoids the crash.

EditorPython · JSX
PreviewUpdates on Run Tests
Loading preview…
Tests
Should use .get() with a default for the 'network' key
Should use .get() for 'timeout' and 'retries' too
Should NOT directly index config["network"]["timeout"] without .get()