Skip to content

fix: replace bare except with except Exception in useragent.py#7296

Open
harshadkhetpal wants to merge 1 commit intovoxel51:developfrom
harshadkhetpal:fix/bare-except-useragent
Open

fix: replace bare except with except Exception in useragent.py#7296
harshadkhetpal wants to merge 1 commit intovoxel51:developfrom
harshadkhetpal:fix/bare-except-useragent

Conversation

@harshadkhetpal
Copy link
Copy Markdown
Contributor

@harshadkhetpal harshadkhetpal commented Apr 2, 2026

Summary

Replace bare except: with except Exception: in fiftyone/utils/useragent.py.

Bare except: silently catches all exceptions — including SystemExit, KeyboardInterrupt, and GeneratorExit — which can suppress critical signals and make programs impossible to interrupt. except Exception: is the correct, Pythonic choice when the intent is to swallow non-fatal errors.

Change:

# Before
    except:
        pass

# After
    except Exception:
        pass

Testing

No behavior change — style/correctness fix only. The pass block continues to swallow non-fatal exceptions while correctly allowing SystemExit and KeyboardInterrupt to propagate.

Summary by CodeRabbit

  • Chores
    • Improved exception handling robustness in user-agent utilities to prevent unintended suppression of critical system errors.

Bare `except:` catches all exceptions including SystemExit, KeyboardInterrupt
and GeneratorExit. Using `except Exception:` is more precise and follows
Python best practices (PEP 8).

Fixes #noissue
@harshadkhetpal harshadkhetpal requested a review from a team as a code owner April 2, 2026 21:58
@voxel51-bot
Copy link
Copy Markdown
Collaborator

Thanks for opening this pull request, @harshadkhetpal! 🎉

A maintainer will review your changes soon. In the meantime, please ensure:

  • You filled out the PR template above, completely to the best of your knowledge
  • You include tests (if applicable)
  • You read the contribution guide

Helpful resources:

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 046934a9-5d38-47aa-9412-7e5f9a77d378

📥 Commits

Reviewing files that changed from the base of the PR and between bd3db37 and 1ad1e02.

📒 Files selected for processing (1)
  • fiftyone/utils/useragent.py

Walkthrough

Updated exception handling in fiftyone/utils/useragent.py from a bare except: clause to except Exception:. This change narrows exception catching to exclude non-Exception errors such as system exits and keyboard interrupts. The function logic and control flow remain otherwise unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the key aspects of the change and rationale, but is missing several required template sections: Related Issues, testing details, and release notes section. Complete the template by adding the Related Issues section, detailed testing information, and the Release Notes section with user-facing impact assessment.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the primary change: replacing bare except with except Exception in useragent.py.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Burhan-Q
Copy link
Copy Markdown
Member

Burhan-Q commented Apr 3, 2026

@harshadkhetpal think you can push changes to all the bare except locations in the source for consistency? I found at least 176 occurrences on the develop branch, and I think it makes sense to update all at once. One instance my pattern matched was a docstring, which won't need updating. I see one instance with an inline # pylint: disable=bare-except, which I suspect can be removed once updated.

grep -rn "^\s*except\s*:" --include="*.py" fiftyone/
All bare exceptions found

fiftyone/migrations/revisions/v0_20_0.py:159:        except:
fiftyone/migrations/revisions/v0_20_0.py:176:                except:
fiftyone/migrations/revisions/v0_20_0.py:199:    except:
fiftyone/migrations/revisions/admin/v0_15_1.py:30:    except:
fiftyone/migrations/revisions/v0_19_0.py:94:            except:
fiftyone/migrations/revisions/v0_19_0.py:111:    except:
fiftyone/migrations/revisions/v0_19_0.py:118:    except:
fiftyone/migrations/revisions/v0_19_0.py:123:    except:
fiftyone/migrations/revisions/v0_19_0.py:128:    except:
fiftyone/core/service.py:252:        except:
fiftyone/core/service.py:262:        except:
fiftyone/core/service.py:317:        except:
fiftyone/core/config.py:327:        except:
fiftyone/core/config.py:383:            except:
fiftyone/core/config.py:999:    except:
fiftyone/core/config.py:1004:    except:
fiftyone/core/config.py:1025:    except:
fiftyone/core/clips.py:128:        except:
fiftyone/core/annotation/generate_label_schemas.py:130:    except :class:`fiftyone.core.labels.GeoLocation`,  # don't change, this is a docstring
fiftyone/core/stages.py:7973:            except:
fiftyone/core/stages.py:7985:    except:
fiftyone/core/stages.py:7993:    except:
fiftyone/core/stages.py:8186:        except:
fiftyone/core/stages.py:8352:        except:
fiftyone/core/stages.py:8531:        except:
fiftyone/core/stages.py:8687:        except:
fiftyone/core/stages.py:8899:        except:
fiftyone/core/stages.py:9087:    except:
fiftyone/core/dataset.py:260:        except:
fiftyone/core/dataset.py:385:        except:
fiftyone/core/dataset.py:5155:        except:
fiftyone/core/dataset.py:9777:        except:
fiftyone/core/dataset.py:9833:    except:
fiftyone/core/odm/database.py:330:    except:
fiftyone/core/odm/database.py:340:    except:
fiftyone/core/odm/database.py:871:    except:
fiftyone/core/odm/database.py:1134:        except:
fiftyone/core/odm/database.py:1171:        except:
fiftyone/core/odm/database.py:1330:        except:
fiftyone/core/odm/database.py:1496:        except:
fiftyone/core/odm/database.py:1598:        except:
fiftyone/core/odm/database.py:2167:        except:
fiftyone/core/odm/database.py:2221:    except:
fiftyone/core/odm/utils.py:711:        except:
fiftyone/core/odm/document.py:666:        except:
fiftyone/core/view.py:122:        except:
fiftyone/core/context.py:16:except:
fiftyone/core/cli.py:2056:        except:
fiftyone/core/cli.py:4044:    except:
fiftyone/core/cli.py:5267:    except:
fiftyone/core/cli.py:5272:    except:
fiftyone/core/cli.py:5296:            except:
fiftyone/core/collections.py:855:        except:
fiftyone/core/collections.py:979:        except:
fiftyone/core/collections.py:1009:        except:
fiftyone/core/collections.py:2890:        except:
fiftyone/core/collections.py:11017:                    except:
fiftyone/core/collections.py:11619:            except:
fiftyone/core/collections.py:12077:        except:
fiftyone/core/collections.py:13531:        except:
fiftyone/core/collections.py:13536:        except:
fiftyone/core/collections.py:13541:        except:
fiftyone/core/collections.py:13546:        except:
fiftyone/core/utils.py:68:    except:
fiftyone/core/utils.py:70:except:
fiftyone/core/utils.py:2639:    except:
fiftyone/core/utils.py:2803:        except:
fiftyone/core/storage.py:917:    except:
fiftyone/core/runs.py:358:        except:
fiftyone/core/runs.py:433:            except:
fiftyone/core/runs.py:444:            except:
fiftyone/core/runs.py:1002:        except:
fiftyone/core/plots/matplotlib.py:946:        except:
fiftyone/core/aggregations.py:1125:            except:
fiftyone/core/validation.py:119:        except:
fiftyone/core/validation.py:280:        except:
fiftyone/core/session/session.py:23:except:
fiftyone/core/session/session.py:512:        except:
fiftyone/core/session/session.py:1279:    except:
fiftyone/core/session/session.py:1289:    except:
fiftyone/core/session/notebooks.py:18:except:
fiftyone/operators/utils.py:55:        except:
fiftyone/operators/executor.py:187:    except:
fiftyone/plugins/definitions.py:178:        except:
fiftyone/plugins/core.py:82:        except:
fiftyone/plugins/core.py:440:    except:
fiftyone/plugins/core.py:596:        except:
fiftyone/plugins/core.py:656:                    except:
fiftyone/plugins/core.py:696:    except:
fiftyone/plugins/context.py:198:        except:
fiftyone/plugins/context.py:253:        except:
fiftyone/plugins/secrets.py:128:    except:  # pylint: disable=bare-except
fiftyone/server/query.py:122:        except:
fiftyone/server/query.py:144:        except:
fiftyone/server/query.py:520:        except:
fiftyone/server/query.py:621:        except:
fiftyone/server/query.py:677:            except:
fiftyone/server/query.py:682:            except:
fiftyone/server/query.py:689:            except:
fiftyone/server/mutation.py:231:            except:
fiftyone/server/utils/__init__.py:71:        except:
fiftyone/server/lightning.py:417:    except:
fiftyone/server/lightning.py:495:        except:
fiftyone/server/routes/geo.py:78:        except:
fiftyone/utils/coco.py:2280:    except:
fiftyone/utils/labels.py:1205:    except:
fiftyone/utils/openimages.py:556:    except:
fiftyone/utils/openimages.py:589:    except:
fiftyone/utils/openimages.py:622:    except:
fiftyone/utils/openimages.py:659:    except:
fiftyone/utils/useragent.py:17:    except:
fiftyone/utils/clip/tokenizer.py:136:                except:
fiftyone/utils/labelbox.py:1071:        except:
fiftyone/utils/labelbox.py:1974:            except:
fiftyone/utils/labelbox.py:2195:        except:
fiftyone/utils/labelbox.py:2915:    except:
fiftyone/utils/labelbox.py:2920:    except:
fiftyone/utils/huggingface.py:239:            except:
fiftyone/utils/huggingface.py:854:    except:
fiftyone/utils/huggingface.py:1432:    except:
fiftyone/utils/yolo.py:1289:    except:
fiftyone/utils/eta.py:548:    except:
fiftyone/utils/voc.py:815:    except:
fiftyone/utils/voc.py:820:    except:
fiftyone/utils/eval/coco.py:825:            except:
fiftyone/utils/eval/regression.py:369:            except:
fiftyone/utils/eval/openimages.py:838:    except:
fiftyone/utils/eval/activitynet.py:289:                except:
fiftyone/utils/github.py:84:                except:
fiftyone/utils/github.py:269:        except:
fiftyone/utils/labelstudio.py:686:    except:
fiftyone/utils/beam.py:741:                except:
fiftyone/utils/annotations.py:1282:            except:
fiftyone/utils/annotations.py:1403:            except:
fiftyone/utils/geojson.py:100:        except:
fiftyone/utils/geojson.py:239:        except:
fiftyone/utils/data/parsers.py:205:    except:
fiftyone/utils/data/parsers.py:1076:            except:
fiftyone/utils/data/parsers.py:1207:        except:
fiftyone/utils/data/parsers.py:1382:            except:
fiftyone/utils/data/importers.py:519:        except:
fiftyone/utils/data/ingestors.py:52:            except:
fiftyone/utils/data/ingestors.py:184:        except:
fiftyone/utils/data/ingestors.py:297:        except:
fiftyone/utils/data/ingestors.py:412:        except:
fiftyone/utils/data/ingestors.py:516:        except:
fiftyone/utils/data/exporters.py:545:        except:
fiftyone/utils/data/exporters.py:575:        except:
fiftyone/utils/data/exporters.py:618:        except:
fiftyone/utils/data/exporters.py:653:        except:
fiftyone/utils/data/exporters.py:908:                    except:
fiftyone/utils/video.py:953:        except:
fiftyone/utils/cvat.py:3485:                except:
fiftyone/utils/cvat.py:3520:                    except:
fiftyone/utils/cvat.py:7040:        except:
fiftyone/utils/cvat.py:7121:        except:
fiftyone/utils/cvat.py:7655:    except:
fiftyone/utils/cvat.py:7664:    except:
fiftyone/utils/cvat.py:7669:    except:
fiftyone/utils/cvat.py:8075:        except:
fiftyone/utils/image.py:512:        except:
fiftyone/utils/scale.py:895:        except:
fiftyone/utils/kinetics.py:253:                except:
fiftyone/utils/activitynet.py:732:                except:
fiftyone/zoo/datasets/tf.py:556:        except:
fiftyone/zoo/datasets/tf.py:575:        except:
fiftyone/zoo/datasets/__init__.py:244:    except:
fiftyone/zoo/datasets/__init__.py:740:    except:
fiftyone/zoo/datasets/__init__.py:1740:                except:
fiftyone/zoo/datasets/torch.py:592:    except:
fiftyone/zoo/datasets/base.py:3404:    except:
fiftyone/zoo/datasets/base.py:3412:    except:
fiftyone/zoo/datasets/base.py:3420:    except:
fiftyone/zoo/datasets/base.py:3427:    except:
fiftyone/zoo/models/__init__.py:826:    except:
fiftyone/factory/repos/delegated_operation.py:268:        except:

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (c35f162) to head (1ad1e02).
⚠️ Report is 2303 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7296      +/-   ##
===========================================
+ Coverage    99.10%   99.25%   +0.15%     
===========================================
  Files           85      101      +16     
  Lines        23353    29047    +5694     
===========================================
+ Hits         23143    28830    +5687     
- Misses         210      217       +7     
Flag Coverage Δ
python 99.25% <ø> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants