Skip to content

Extended error handling when a node fails#143

Merged
jonatan-qm merged 18 commits into
mainfrom
feat/extended-error-handling
Jan 6, 2026
Merged

Extended error handling when a node fails#143
jonatan-qm merged 18 commits into
mainfrom
feat/extended-error-handling

Conversation

@jonatan-qm

@jonatan-qm jonatan-qm commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

Part of solving https://quantum-machines.atlassian.net/browse/QUAL-1645

Enhances error reporting for calibration node failures by providing the user with richer debugging context, including source code snippets, simplified tracebacks, and action execution history. This information is displayed by the frontend.

This change also affects qualibrate-core, where the qua-platform/qualibrate-runner#64 needs to be merged before this one is merged, for everything to be working.

Key Changes

  • Extended RunError model with details_headline and details fields for structured error context
  • Simplified traceback generation that filters out framework overhead and focuses on user code
  • Source code snippet extraction showing the exact location where errors occurred (with surrounding context)
  • Action execution tracking including completed, skipped, and failed actions
  • Comprehensive unit tests for action.py and action_manager.py (854 new test lines)
  • Improved code documentation with clarifying comments in action framework modules

Technical Implementation

The error handling for failed nodes now provides:

  • Error headlines: Concise descriptions like "Failed action 'execute_qua_program'" or "Failure in node body"
  • Error details: Markdown-formatted context including:
    • Source code snippet with error marker
    • Simplified traceback showing only relevant frames
    • Action execution history (completed/skipped actions)
  • Smart traceback simplification: Removes framework overhead while preserving the full call chain within user code

Testing

  • Added comprehensive unit tests covering action registration, execution, error handling, and state management.
  • Updated README.md with testing instructions.

@jonatan-qm jonatan-qm marked this pull request as ready for review November 26, 2025 20:52
@jonatan-qm jonatan-qm requested review from Elad-Zaharan and removed request for natangqm November 27, 2025 08:40
Comment thread qualibrate/qualibration_node.py
Comment thread qualibrate/qualibration_node.py Outdated
start_idx = node_frames_after_framework[0]
else:
# Fallback: use first node frame
# (shouldn't happen in normal execution)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here, does it mean that the framework code ran after the users code? if that's the case maybe we could add it as a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a weird edge case, and I added this just to be sure. It is because it parses a trace and tries to remove all irrelevant information. But this is not likely to happen.

Comment thread qualibrate/qualibration_node.py
Comment thread qualibrate/runnables/run_action/action.py
Comment thread qualibrate/runnables/run_action/action.py
Comment thread tests/unit/test_runnables/test_run_action/test_action.py
Comment thread tests/unit/test_runnables/test_run_action/test_action.py

@pytest.fixture
def mock_node(self):
"""Provide a mock QualibrationNode."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

code duplication

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right. I am moving this to conftest.py.


@pytest.fixture
def mock_manager(self):
"""Provide a mock ActionManager."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same as the first mock with some extensions, could we maybe extend the first mock manager and make it to whole file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right. I am moving this to conftest.py.

return Mock()

@pytest.fixture
def mock_node(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we might consider scoping here aswell so nothing override mutable objects this fixture returns

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right. I am moving this to conftest.py.

Comment thread tests/unit/test_runnables/test_run_action/test_action_manager.py
class TestRunAction:
"""Tests for the run_action method."""

@pytest.fixture

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same fixture here, maybe we can extract it to conftest, seems like in this file it appears a lot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I will do that now.


@pytest.fixture
def mock_node(self):
"""Provide a mock QualibrationNode."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

here aswell, maybe we can extract to conftest because we use it a lot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I will do that now.

"""Tests for the register_action decorator."""

@pytest.fixture
def manager(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same fixture

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I will do that now.


@pytest.fixture
def mock_node(self):
"""Provide a mock QualibrationNode."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

pretty similar to previous one, maybe we can extend it here but might declare in conftest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I will do that now.

Comment thread tests/unit/test_runnables/test_run_action/test_action_manager.py
Comment thread tests/unit/test_runnables/test_run_action/test_action_manager.py
@jonatan-qm jonatan-qm merged commit 6d9eed5 into main Jan 6, 2026
2 of 3 checks passed
@jonatan-qm jonatan-qm deleted the feat/extended-error-handling branch January 6, 2026 10:17
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