Skip to content

Comments

Missing config file errors are not logged to event log in file-extractor#506

Open
Yaseen-A-Khan wants to merge 1 commit intomasterfrom
fix/reraise-invalid-config-error
Open

Missing config file errors are not logged to event log in file-extractor#506
Yaseen-A-Khan wants to merge 1 commit intomasterfrom
fix/reraise-invalid-config-error

Conversation

@Yaseen-A-Khan
Copy link

@Yaseen-A-Khan Yaseen-A-Khan commented Feb 20, 2026

This PR adds changes as per the DOG-5806 - Missing config file errors are not logged to event log in file-extractor

Problem: In Extractor.__enter__ enter when _initial_load_config raised an InvalidConfigError, the code caught it, printed to stderr, and called sys.exit(1). This swallowed the exception, killed the process, and gave callers no way to handle the error.
Fix:
cognite/extractorutils/base.py -- Removed the try/except block around _initial_load_config() so InvalidConfigError propagates naturally to the caller. Removed the now-unused import sys.
tests/tests_unit/test_base.py -- Added test_enter_raises_on_invalid_config that mocks _initial_load_config to raise InvalidConfigError and asserts it propagates from __enter__.

@Yaseen-A-Khan Yaseen-A-Khan requested a review from a team as a code owner February 20, 2026 18:59
@gemini-code-assist
Copy link

Summary of Changes

Hello @Yaseen-A-Khan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the error handling mechanism within the Extractor class, specifically addressing how InvalidConfigError is managed during the initial configuration load. By removing a try/except block that previously swallowed this critical exception and forcefully exited the process, the system now allows configuration errors to propagate up the call stack. This change provides callers with the ability to handle configuration issues gracefully, rather than encountering an abrupt termination, thereby improving the robustness and diagnosability of applications using the extractor utilities.

Highlights

  • Error Handling Improvement: Modified the Extractor.__enter__ method to no longer catch InvalidConfigError during initial configuration loading, allowing the exception to propagate naturally to the caller for more robust error management.
  • Dependency Cleanup: Removed the sys module import from cognite/extractorutils/base.py as it is no longer needed after the changes to error handling.
  • Enhanced Test Coverage: Added a new unit test, test_enter_raises_on_invalid_config, to explicitly verify that InvalidConfigError correctly propagates from the Extractor.__enter__ method as intended.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cognite/extractorutils/base.py
    • Removed import sys statement.
    • Removed from cognite.extractorutils.exceptions import InvalidConfigError statement.
    • Removed the try...except InvalidConfigError block from the __enter__ method, allowing the exception to propagate.
  • tests/tests_unit/test_base.py
    • Added from cognite.extractorutils.exceptions import InvalidConfigError statement.
    • Added a new test function test_enter_raises_on_invalid_config to assert that InvalidConfigError is raised by Extractor.__enter__.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses an important issue where an invalid configuration would cause the extractor process to terminate abruptly. By removing the try...except block in Extractor.__enter__, the InvalidConfigError is now allowed to propagate to the caller. This is a significant improvement in error handling, making the extractor more robust and predictable when used as a library component. The change is accompanied by a well-written unit test that confirms the new behavior. The implementation is clean and effective, and I have no further recommendations.

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.45%. Comparing base (dd94c20) to head (ea002a7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #506      +/-   ##
==========================================
+ Coverage   81.13%   81.45%   +0.32%     
==========================================
  Files          43       43              
  Lines        4208     4201       -7     
==========================================
+ Hits         3414     3422       +8     
+ Misses        794      779      -15     
Files with missing lines Coverage Δ
cognite/extractorutils/base.py 60.84% <100.00%> (+3.70%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant