Skip to content

fix(errors): parse structured server errors carrying a legacy C-layer banner - #3408

Open
PProfizi wants to merge 4 commits into
mainfrom
pprofizi/fix/structured-error-legacy-banner
Open

fix(errors): parse structured server errors carrying a legacy C-layer banner#3408
PProfizi wants to merge 4 commits into
mainfrom
pprofizi/fix/structured-error-legacy-banner

Conversation

@PProfizi

@PProfizi PProfizi commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

This pull request enhances the handling and formatting of DPF server error messages, especially those containing structured error payloads with legacy banners. The changes improve error readability for both users and developers by standardizing error output and ensuring that structured errors are properly parsed and displayed.

Error handling improvements:

  • Added a new format_dpf_error function in src/ansys/dpf/gate/errors.py to extract and render human-readable messages from possibly structured DPF error strings, including those prefixed with legacy banners.
  • Updated read_stdout in src/ansys/dpf/core/server_types.py to use format_dpf_error when raising runtime errors, ensuring consistent error formatting.

Structured error parsing enhancements:

  • Improved _parse_structured_error in src/ansys/dpf/gate/errors.py to recognize and strip legacy error banners before parsing JSON, allowing for better detection of structured errors.
  • Added a regular expression _LEGACY_BANNER to identify and remove legacy error prefixes [1] [2].

Testing and validation:

  • Added comprehensive tests in tests/test_server_errors.py to verify handling of structured errors with legacy banners, multi-line errors, and plain messages, ensuring the new formatting logic works as intended.

Imports and code organization:

  • Added the new format_dpf_error to the public API of src/ansys/dpf/core/errors.py.

…r banner

The CAPI raise path prefixes the structured JSON error with a legacy C-layer
banner ("a '...' error occurred: {...}"), which defeated the
_parse_structured_error startswith("{") check and caused the raw JSON to be
printed. Strip the banner before parsing so these errors render as a readable
root-cause message plus the operator-chain note.
@PProfizi PProfizi self-assigned this Aug 25, 2026
@PProfizi
PProfizi requested a review from a team as a code owner August 25, 2026 08:57
@PProfizi PProfizi added the bug Something isn't working label Aug 25, 2026
Comment thread tests/test_server_errors.py Outdated
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.75%. Comparing base (11c953e) to head (0a98ccd).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3408       +/-   ##
===========================================
+ Coverage   44.70%   82.75%   +38.05%     
===========================================
  Files          95       95               
  Lines       11791    11791               
===========================================
+ Hits         5271     9758     +4487     
+ Misses       6520     2033     -4487     

Server startup failures surface the structured error as raw JSON prefixed
with a "DPF Error:" banner and are raised as a plain RuntimeError, bypassing
DPFServerException. Add a reusable format_dpf_error() helper (banner-aware,
tolerant of the payload appearing on one line of multi-line stderr) and use it
when raising the startup RuntimeError so the root-cause message and operator
chain are shown instead of the raw dictionary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants