Skip to content

EDGE-278 Log Forbidden message is unclear#533

Merged
Yaseen-A-Khan merged 1 commit into
masterfrom
yaseen/403-errorlog
May 21, 2026
Merged

EDGE-278 Log Forbidden message is unclear#533
Yaseen-A-Khan merged 1 commit into
masterfrom
yaseen/403-errorlog

Conversation

@Yaseen-A-Khan
Copy link
Copy Markdown
Contributor

Background

While starting the file extractor main branch, if the application (client ID) doesnt have required permission (case observed) for the cognite API /api/v1/projects/{self._cognite_client.config.project}/odin/checkin, raises a CogntieAPIError with status code 403 and error message "Forbidden" and the log shows only “Forbidden”. The log could be improved.

Image of previous forbidden log

Summary

This PR addresses error handling for authentication and authorization failures from CDF:

  • 403 Forbidden support: Adds explicit handling for 403 errors alongside existing 401 (Unauthorized) errors
  • Improved observability: Clarifies error messages by labeling error codes (e.g., "401 (Unauthorized)") and fixing grammar
  • Test coverage: Parametrizes the fatal hook test to verify both 401 and 403 error paths trigger the handler correctly
Image of update forbidden log

Changes

checkin_worker.py & runtime.py

  • Updated 401 error message: "Got a 401 error" → "Got a 401 (Unauthorized) error"
  • Fixed grammar: "credentials and project is correct" → "credentials and project are correct"
  • Added new elif e.code == 403: block with Forbidden error message

test_checkin_worker.py

  • Parametrized test_on_fatal_hook_is_called with @pytest.mark.parametrize decorator
  • Test runs twice: once for 401, once for 403
  • Added readable ids for test output clarity

Test Plan

  • test_on_fatal_hook_is_called[401-Unauthorized] — verifies fatal hook fires on 401
  • test_on_fatal_hook_is_called[403-Forbidden] — verifies fatal hook fires on 403

- Add handling for 403 (Forbidden) errors in CheckinWorker and Runtime
- Clarify 401 error message with Unauthorized label and fix grammar
- Parametrize test_on_fatal_hook_is_called to verify both 401 and 403 paths
@Yaseen-A-Khan Yaseen-A-Khan requested a review from a team as a code owner May 20, 2026 09:52
Copy link
Copy Markdown

@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 improves error handling for CDF API requests by adding explicit support for 403 (Forbidden) errors and refining the log messages for 401 (Unauthorized) errors in both checkin_worker.py and runtime.py. Additionally, the test suite was updated to include parametrized tests for both status codes. I have no feedback to provide.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.90%. Comparing base (47c32a3) to head (c95614c).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
cognite/extractorutils/unstable/core/runtime.py 0.00% 2 Missing ⚠️
...ite/extractorutils/unstable/core/checkin_worker.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #533      +/-   ##
==========================================
- Coverage   81.97%   81.90%   -0.08%     
==========================================
  Files          43       43              
  Lines        4217     4222       +5     
==========================================
+ Hits         3457     3458       +1     
- Misses        760      764       +4     
Files with missing lines Coverage Δ
...ite/extractorutils/unstable/core/checkin_worker.py 91.17% <66.66%> (+0.13%) ⬆️
cognite/extractorutils/unstable/core/runtime.py 70.08% <0.00%> (-0.58%) ⬇️

... and 1 file with indirect coverage changes

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

Copy link
Copy Markdown
Contributor

@Hmnt39 Hmnt39 left a comment

Choose a reason for hiding this comment

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

LGTM

@Yaseen-A-Khan Yaseen-A-Khan added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label May 20, 2026
Copy link
Copy Markdown

@erlendvollset erlendvollset left a comment

Choose a reason for hiding this comment

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

🦄

@erlendvollset erlendvollset self-assigned this May 21, 2026
@erlendvollset erlendvollset added risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action and removed waiting-for-risk-review Waiting for a member of the risk review team to take an action labels May 21, 2026
@Yaseen-A-Khan Yaseen-A-Khan merged commit 7e07249 into master May 21, 2026
7 checks passed
@Yaseen-A-Khan Yaseen-A-Khan deleted the yaseen/403-errorlog branch May 21, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants