arduino/Arduino · error · KeyError

KeyError(key)

Error message

KeyError(key)

What it means

OrderedDict.pop(key) raises KeyError(key) when the key is absent and no default argument was supplied. If a default is given, it is returned instead; the marker sentinel distinguishes 'no default passed' from a default of None.

Source

Thrown at arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/packages/ordered_dict.py:188

                self[key] = value
        for key, value in kwds.items():
            self[key] = value

    __update = update  # let subclasses override update without breaking __init__

    __marker = object()

    def pop(self, key, default=__marker):
        '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value.
        If key is not found, d is returned if given, otherwise KeyError is raised.

        '''
        if key in self:
            result = self[key]
            del self[key]
            return result
        if default is self.__marker:
            raise KeyError(key)
        return default

    def setdefault(self, key, default=None):
        'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od'
        if key in self:
            return self[key]
        self[key] = default
        return default

    def __repr__(self, _repr_running={}):
        'od.__repr__() <==> repr(od)'
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return '%s()' % (self.__class__.__name__,)

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Supply a default: od.pop(key, None).
  2. Check membership first: `if key in od: od.pop(key)`.
  3. Catch KeyError around the pop when absence is expected.
  4. Log/print od.keys() to spot key spelling or case mismatches.

Example fix

// before
value = od.pop('timeout')
// after
value = od.pop('timeout', None)
if value is None:
    value = DEFAULT_TIMEOUT
Defensive patterns

Strategy: try-catch

Validate before calling

if key in od:
    value = od.pop(key)
else:
    value = default

Try / catch

try:
    value = od.pop(key)
except KeyError:
    value = default  # key was absent and no default given

Prevention

When it happens

Trigger: Calling od.pop('missing_key') with exactly one argument on an OrderedDict that does not contain that key; race where the key is deleted between `in` check and pop.

Common situations: Evicting a session or cache entry that was already removed; typo'd or case-mismatched keys (e.g. 'Config' vs 'config'); assuming dict-style pop semantics without providing a default.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/86f9d5ae4f932c1e. Report an issue: GitHub.