Skip to content

Conversation

@pcrespov
Copy link
Member

@pcrespov pcrespov commented Jun 20, 2025

What do these changes do?

  • Improves robustness by correcting how unexpected exceptions are handled.
  • Now all 5XX are logged with supportID (i.e. OEC!)

⚠️ Important Note

Avoid including the string representation of raw exceptions in HTTP responses:

try:
    # ...
except Exception as err:
    raise web.HTTPInternalServerError(text="Some controlled human readable message")  # ✅ Proper handling
    # raise web.HTTPInternalServerError(text=f"{err}")  # ❌ Don't expose exception details

Related issue/s

How to test

cd packages/servicelib
make "install-dev[aiohttp]"
pytest -vv tests/aiohttp/test_rest_responses.py

Dev-ops

None

@pcrespov pcrespov self-assigned this Jun 20, 2025
@pcrespov pcrespov added a:services-library issues on packages/service-libs release Preparation for pre-release/release labels Jun 20, 2025
@pcrespov pcrespov marked this pull request as ready for review June 20, 2025 08:54
@giancarloromeo giancarloromeo changed the title 🐛 web-api: Fixes handling of unexpected erros 🐛 web-api: Fixes handling of unexpected errors Jun 20, 2025
@pcrespov pcrespov requested a review from sanderegg June 20, 2025 08:55
@codecov
Copy link

codecov bot commented Jun 20, 2025

Codecov Report

Attention: Patch coverage is 76.59574% with 11 lines in your changes missing coverage. Please review.

Project coverage is 87.90%. Comparing base (c1d1065) to head (68bb19c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7939      +/-   ##
==========================================
  Coverage   87.90%   87.90%              
==========================================
  Files        1846     1428     -418     
  Lines       71225    59370   -11855     
  Branches     1220      621     -599     
==========================================
- Hits        62609    52190   -10419     
+ Misses       8264     6969    -1295     
+ Partials      352      211     -141     
Flag Coverage Δ
integrationtests 64.23% <50.00%> (+11.72%) ⬆️
unittests 86.22% <76.59%> (-0.41%) ⬇️
Components Coverage Δ
api ∅ <ø> (∅)
pkg_aws_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library ∅ <ø> (∅)
pkg_notifications_library ∅ <ø> (∅)
pkg_postgres_database ∅ <ø> (∅)
pkg_service_integration ∅ <ø> (∅)
pkg_service_library 72.52% <75.67%> (-0.15%) ⬇️
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 85.10% <ø> (+0.05%) ⬆️
agent 96.29% <ø> (ø)
api_server 92.31% <ø> (ø)
autoscaling 96.03% <ø> (ø)
catalog 92.29% <ø> (ø)
clusters_keeper 99.13% <ø> (ø)
dask_sidecar 91.79% <ø> (ø)
datcore_adapter 97.94% <ø> (ø)
director 76.73% <ø> (ø)
director_v2 91.00% <ø> (-0.12%) ⬇️
dynamic_scheduler 96.69% <ø> (ø)
dynamic_sidecar 90.09% <ø> (ø)
efs_guardian 89.65% <ø> (ø)
invitations 93.00% <ø> (ø)
payments 92.57% <ø> (ø)
resource_usage_tracker 89.00% <ø> (-0.11%) ⬇️
storage 87.53% <ø> (-0.32%) ⬇️
webclient ∅ <ø> (∅)
webserver 87.64% <80.00%> (+0.46%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1d1065...68bb19c. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR standardizes error handling by removing the skip_internal_error_details toggle, ensuring internal exceptions never leak raw details, and cleans up related middleware code.

  • Dropped the skip_internal_error_details parameter from create_http_error and simplified its logic.
  • Updated middlewares to stop branching on environment flags and renamed variables for consistency.
  • Adjusted tests to remove obsolete skip_details parameter.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/service-library/tests/aiohttp/test_rest_responses.py Removed the obsolete skip_details parameter and related invocations in tests_exception_to_response.
packages/service-library/src/servicelib/aiohttp/rest_responses.py Removed the skip_internal_error_details parameter and simplified the internal-error branch.
packages/service-library/src/servicelib/aiohttp/rest_middlewares.py Removed environment-based detail toggles, introduced a single error_message variable, and renamed resp to response.
packages/service-library/src/servicelib/aiohttp/monitoring.py Renamed resp to response, removed default reason text, and dropped special cases for cancelled/HTTPServerError.
Comments suppressed due to low confidence (1)

packages/service-library/src/servicelib/aiohttp/rest_responses.py:88

  • The docstring references skipping internal error details, but the skip_internal_error_details parameter was removed; update the documentation to reflect the current behavior.
    exceptions to the client in production

Copy link
Collaborator

@matusdrobuliak66 matusdrobuliak66 left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

thanks!

Copy link
Contributor

@bisgaard-itis bisgaard-itis left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix

@pcrespov pcrespov added this to the Engage milestone Jun 20, 2025
@pcrespov pcrespov force-pushed the is7932/fix-handling-unexpected-exceptions branch from 4b494c4 to 8ac1c97 Compare June 20, 2025 15:59
@pcrespov pcrespov enabled auto-merge (squash) June 20, 2025 15:59
@pcrespov
Copy link
Member Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Jun 20, 2025

queue

🟠 Waiting for conditions to match

  • any of: [🔀 queue conditions]
    • all of: [📌 queue conditions of queue default]
      • any of: [🛡 GitHub branch protection]
        • check-neutral = deploy to dockerhub
        • check-skipped = deploy to dockerhub
        • check-success = deploy to dockerhub
      • any of: [🛡 GitHub branch protection]
        • check-neutral = system-tests
        • check-skipped = system-tests
        • check-success = system-tests
      • any of: [🛡 GitHub branch protection]
        • check-neutral = unit-tests
        • check-skipped = unit-tests
        • check-success = unit-tests
      • any of: [🛡 GitHub branch protection]
        • check-neutral = integration-tests
        • check-skipped = integration-tests
        • check-success = integration-tests
      • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
      • #approved-reviews-by>=2
      • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
      • #changes-requested-reviews-by=0
      • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
      • #review-threads-unresolved=0
      • -conflict
      • -draft
      • base=master
      • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
      • label!=🤖-do-not-merge
      • label=🤖-automerge
      • any of: [🛡 GitHub branch protection]
        • check-success = check OAS' are up to date
        • check-neutral = check OAS' are up to date
        • check-skipped = check OAS' are up to date
      • any of: [🛡 GitHub branch protection]
        • check-success = build-test-images (frontend) / build-test-images
        • check-neutral = build-test-images (frontend) / build-test-images
        • check-skipped = build-test-images (frontend) / build-test-images
  • -closed [📌 queue requirement]
  • -conflict [📌 queue requirement]
  • -draft [📌 queue requirement]
  • any of: [📌 queue -> configuration change requirements]
    • -mergify-configuration-changed
    • check-success = Configuration changed

@pcrespov pcrespov added the 🤖-automerge marks PR as ready to be merged for Mergify label Jun 20, 2025
@pcrespov
Copy link
Member Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2025

queue

🛑 The pull request could not be merged

This could be related to an activated branch protection or ruleset rule that prevents us from merging. (details: 3 of 6 required status checks are expected.)

@pcrespov pcrespov force-pushed the is7932/fix-handling-unexpected-exceptions branch from 89dcb0d to 68bb19c Compare June 22, 2025 14:56
@sonarqubecloud
Copy link

@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #7939 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (details: 3 of 6 required status checks are expected.).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

@pcrespov
Copy link
Member Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Jun 22, 2025

queue

🛑 The pull request has been removed from the queue default

Pull request #7939 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (details: 3 of 6 required status checks are expected.).

You can take a look at Queue: Embarked in merge queue check runs for more details about the failure.

@pcrespov pcrespov merged commit 8116821 into ITISFoundation:master Jun 22, 2025
146 of 149 checks passed
@pcrespov pcrespov deleted the is7932/fix-handling-unexpected-exceptions branch June 22, 2025 16:25
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request Jun 23, 2025
92 tasks
@matusdrobuliak66 matusdrobuliak66 mentioned this pull request Aug 5, 2025
88 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-automerge marks PR as ready to be merged for Mergify a:services-library issues on packages/service-libs release Preparation for pre-release/release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants