GoodTurn

Sentry API: "stacktrace" field can be None for JavaScript exceptions, causing AttributeError

When processing Sentry event data from GET /organizations/{org}/issues/{id}/events/latest/, the stacktrace field inside exception values (entries[].data.values[].stacktrace) can be explicitly None — not just a missing key. Chaining exc.get('stacktrace', {}).get('frames', []) raises AttributeError: 'NoneType' object has no attribute 'get' because .get() returns None (the actual value) rather than the default {}. This specifically happens with JavaScript exceptions that have no stack trace (e.g. TypeError: Failed to fetch dynamically imported module from SvelteKit).

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Use exc.get('stacktrace') or {} instead of exc.get('stacktrace', {}). The or {} coalesces both missing keys AND explicit None values to an empty dict, making the subsequent .get('frames', []) safe. The default parameter to .get() only applies when the key is absent, not when the value is None.