Skip to content

chore(logging): disable traceback for controlled exceptions#52

Open
gkostkowski wants to merge 3 commits into
developfrom
feature/ERS1-262/improved-logging
Open

chore(logging): disable traceback for controlled exceptions#52
gkostkowski wants to merge 3 commits into
developfrom
feature/ERS1-262/improved-logging

Conversation

@gkostkowski

@gkostkowski gkostkowski commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This change addresses TEDSWS-534 Another case of an uncontrolled exception and TEDSWS-529 The ERE throws an exception then the ERS sends an entity of an non-configured type.

Summary

Replace the single log.exception in EntityResolutionService.process_request with a two-tier catch:

  • Controlled exceptions (ValueError, ConflictError): logged via log.error — single line, no traceback, typed EREErrorResponse with actual error type and message.
  • Uncontrolled exceptions (everything else): caught as fallback via log.exception — full traceback retained, generic EREErrorResponse (InternalError) that does not leak internal details.

Top-level entrypoint catches (app.py, queue_worker.py) remain unchanged.

Before

ERROR ere.services.entity_resolution_service Resolution error for mention dcebda76-e037-4993-8dd3-6b8ab43d89e2
Traceback (most recent call last):
  File ".../entity_resolution_service.py", line 462, in process_request
    resolution_outcome = resolve_to_result(
  File ".../entity_resolution_service.py", line 335, in resolve_to_result
    mention = mapper.map_entity_mention_to_domain(entity_mention)
  File ".../rdf_mapper_impl.py", line 72, in map_entity_mention_to_domain
    raise ValueError(
ValueError: No rdf_mapping configured for entity_type 'PROCEDURE'
ERROR ere.services.entity_resolution_service Resolution error for mention 5c2e2c2a-614f-40d2-94e0-201b0f2884bc
Traceback (most recent call last):
  File ".../entity_resolution_service.py", line 462, in process_request
    ...
  File ".../entity_resolution_service.py", line 236, in check_conflict
    raise ConflictError(
ere.models.exceptions.ConflictError: Mention 'e74cb...' was already resolved with different content. Existing: {...}, Incoming: {...}

After

Controlled (no traceback):

ERROR ere.services.entity_resolution_service Resolution error for mention dcebda76-e037-4993-8dd3-6b8ab43d89e2: No rdf_mapping configured for entity_type 'PROCEDURE'
ERROR ere.services.entity_resolution_service Resolution error for mention 5c2e2c2a-614f-40d2-94e0-201b0f2884bc: Mention '5c2e2c2a-614f-40d2-94e0-201b0f2884bc' was already resolved with different content. Existing: {'legal_name': 'EUROPEAN ENVIRONMENT AGENCY 3', ...}, Incoming: {'legal_name': 'EUROPEAN ENVIRONMENT AGENCY 3', 'legal_identifier': 'AE-30466575', ...}

Uncontrolled — crafted/hypothetical example to illustrate the fallback behavior (traceback retained):

ERROR ere.services.entity_resolution_service Unexpected error for mention f3a1b2c3-d4e5-6789-0abc-def012345678
Traceback (most recent call last):
  File ".../entity_resolution_service.py", line 461, in process_request
    ...
TypeError: 'NoneType' object is not subscriptable

Copilot AI review requested due to automatic review settings July 8, 2026 07:40

Copilot AI left a comment

Copy link
Copy Markdown

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 adjusts service-layer logging so controlled resolution failures in EntityResolutionService.process_request are emitted as single-line ERROR logs without Python tracebacks, while keeping traceback logging at higher-level entrypoints for unexpected failures.

Changes:

  • Replaced log.exception(...) with log.error(...) in EntityResolutionService.process_request to suppress tracebacks during resolution failures.
  • Expanded the error log message to include the exception message inline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +491 to +495
except Exception as exc: # pylint: disable=broad-exception-caught
log.exception(
"Resolution error for mention %s",
log.error(
"Resolution error for mention %s: %s",
request.ere_request_id,
exc,
@gkostkowski gkostkowski force-pushed the feature/ERS1-262/improved-logging branch from 45a493f to c6eadff Compare July 8, 2026 10:17
Controlled exceptions (ValueError, ConflictError) are logged with
log.error (no traceback, typed response). Uncontrolled exceptions are
caught as fallback with log.exception (full traceback, generic
InternalError response). Adds top-level ConflictError import.
@gkostkowski gkostkowski force-pushed the feature/ERS1-262/improved-logging branch from c6eadff to 88b97f9 Compare July 8, 2026 10:21
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

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.

2 participants