Skip to content

feat: Augment schema parser error messages - #277

Open
tbkr wants to merge 3 commits into
developfrom
feature/schema-parser-error-msg
Open

feat: Augment schema parser error messages#277
tbkr wants to merge 3 commits into
developfrom
feature/schema-parser-error-msg

Conversation

@tbkr

@tbkr tbkr commented May 8, 2026

Copy link
Copy Markdown
Contributor

Description

Augment schema parser error messages. Now showing in which step of the schema file parsing the error is occurring.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

🌈🌦️📖🚧 Documentation FDB 🚧📖🌦️🌈
https://sites.ecmwf.int/docs/fdb/pull-requests/PR-277

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 aims to improve diagnosability of FDB schema parsing failures by adding higher-level context (which parsing phase failed) to schema parser error handling, and introduces a small test suite + fixtures to exercise broken schema inputs.

Changes:

  • Add parsing-stage context around schema parsing exceptions (types parsing vs rules parsing).
  • Wrap schema-load parsing errors with additional file-path context.
  • Add a new parsing test target with schema fixtures (valid schema and several intentionally broken schemas).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/fdb5/rules/SchemaParser.cc Adds try/catch blocks and logging to annotate errors during type/rule parsing phases.
src/fdb5/rules/Schema.cc Wraps StreamParser::Error to add schema path context when load fails.
tests/fdb/CMakeLists.txt Registers the new parsing test subdirectory.
tests/fdb/parsing/CMakeLists.txt Adds a new unit test target and copies parsing fixtures into the build tree.
tests/fdb/parsing/test_schema_parsing.cc Adds unit tests intended to exercise broken/valid schema inputs.
tests/fdb/parsing/data/schema Adds a valid schema fixture.
tests/fdb/parsing/data/schema_incomplete_rule Adds a broken schema fixture (missing closing bracket).
tests/fdb/parsing/data/broken_schema_no_rule Adds a fixture with only type definitions and no rules.
tests/fdb/parsing/data/broken_types_missing_semicolon Adds a broken types fixture (missing semicolon).
tests/fdb/parsing/data/broken_types_no_name Adds a broken types fixture (missing name).
tests/fdb/parsing/data/broken_types_no_type Adds a broken types fixture (missing type).

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

Comment thread src/fdb5/rules/SchemaParser.cc Outdated
Comment thread src/fdb5/rules/SchemaParser.cc Outdated
Comment thread src/fdb5/rules/SchemaParser.cc Outdated
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/Schema.cc Outdated
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread src/fdb5/rules/SchemaParser.cc Outdated
@codecov-commenter

codecov-commenter commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.44970% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.63%. Comparing base (e5a5a47) to head (10b8bb0).

Files with missing lines Patch % Lines
src/fdb5/rules/SchemaParser.cc 93.05% 5 Missing ⚠️
tests/fdb/parsing/test_schema_parsing.cc 98.86% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #277      +/-   ##
===========================================
+ Coverage    77.51%   77.63%   +0.12%     
===========================================
  Files          411      412       +1     
  Lines        27553    27677     +124     
  Branches      2769     2771       +2     
===========================================
+ Hits         21358    21488     +130     
+ Misses        6195     6189       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 4 times, most recently from de693b2 to 2d2c36e Compare May 8, 2026 12:54
@tbkr

tbkr commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

The fix from #276 should be merged first.

@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 2 times, most recently from 47c5a6d to daf484f Compare May 11, 2026 13:42
@tbkr
tbkr requested a review from danovaro May 11, 2026 13:43
Comment thread .github/workflows/pyfdb.yml Outdated
Comment thread src/fdb5/rules/SchemaParser.cc Outdated
@caraghbiner

Copy link
Copy Markdown
Member

I agree that 0 rules should be an error.

@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 3 times, most recently from 1d9d990 to b2fd67d Compare May 12, 2026 12:46
@danovaro
danovaro force-pushed the feature/schema-parser-error-msg branch from b2fd67d to 6399d0d Compare May 12, 2026 15:13
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 2 times, most recently from ccfef7f to 105c185 Compare June 1, 2026 12:55
@tbkr
tbkr requested review from caraghbiner and Copilot June 1, 2026 13:55
@tbkr

tbkr commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

ecmwf/eckit#293 needs to be merged first.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.

Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/SchemaParser.h
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 3 times, most recently from 9571e30 to d144eea Compare June 1, 2026 14:35
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread tests/fdb/parsing/test_schema_parsing.cc Outdated
Comment thread tests/fdb/parsing/test_schema_parsing.cc
Comment thread src/fdb5/rules/SchemaParser.cc
Comment thread src/fdb5/rules/SchemaParser.cc Outdated
Comment thread .github/workflows/pyfdb.yml Outdated
Comment thread src/fdb5/rules/SchemaParser.h Outdated
Comment thread src/fdb5/rules/Schema.cc
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch from 6e4d27a to c652f94 Compare June 24, 2026 16:04
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch from c652f94 to d21aa42 Compare July 2, 2026 06:48
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 3 times, most recently from d83f04f to 616d007 Compare July 28, 2026 14:19
@tbkr
tbkr requested review from Copilot and simondsmart July 28, 2026 14:21
@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch from 616d007 to 18ab945 Compare July 28, 2026 14:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (6)

src/fdb5/rules/SchemaParser.cc:46

  • Grammar in this error message is incorrect ("character which are"). Also, adding a newline via std::endl ends up in what() and makes matching/printing noisier.
        std::stringstream buf;
        buf << "Schema file contained non-ASCII character which are not supported." << std::endl;
        throw SchemaParser::Error(buf.str(), parser_.line() + 1);

src/fdb5/rules/SchemaParser.cc:312

  • Most parser errors use parser_.line() + 1, but this throws with parser_.line() which is inconsistent and likely off-by-one.
    if (result.size() == 0) {
        std::stringstream buf;
        buf << "SchemaParser::parse: Empty rule list. Didn't find any rule in the provided schema file." << std::endl;
        throw Error(buf.str(), parser_.line());
    }

src/fdb5/rules/Schema.cc:206

  • This wrapper rethrows a fresh SchemaParser::Error without preserving the original error's line number (it will default to 0). It would be more useful to keep the line information from the underlying parse error when rethrowing (if the exception exposes it).
        std::stringstream buf;
        buf << "Error loading FDB schema file: " << path << ". Underlying issue: " << spe.what();
        throw SchemaParser::Error(buf.str());
    }

src/fdb5/rules/SchemaParser.h:41

  • SchemaParser previously initialised the underlying eckit::StreamParser with the (in, true) constructor; the new member initialisation drops that boolean flag, which may change parsing behaviour. If the intent is only to improve error messages, keep the constructor arguments consistent.
    SchemaParser(std::istream& in) : parser_(eckit::StreamParser(in)) {}

src/fdb5/rules/SchemaParser.cc:305

  • Most parser errors use parser_.line() + 1, but this one uses parser_.line() directly, which is likely to report an off-by-one line number compared to other failures.

This issue also appears on line 308 of the same file.

    if (c) {
        throw Error(std::string("SchemaParser::parse: Error parsing rules: remaining char: ") + c, parser_.line());
    }

src/fdb5/rules/Schema.cc:202

  • Catch parser exceptions by const reference (no mutation intended, and it allows catching const exceptions).
    catch (SchemaParser::Error& spe) {

@tbkr
tbkr force-pushed the feature/schema-parser-error-msg branch 3 times, most recently from c0fc206 to 6bb00b6 Compare August 6, 2026 18:12
@danovaro
danovaro force-pushed the feature/schema-parser-error-msg branch from 6bb00b6 to 9aa0a2c Compare August 7, 2026 05:35
tbkr added 3 commits August 25, 2026 16:55
Now showing in which step of the schema file parsing the
error is occurring.
@danovaro
danovaro force-pushed the feature/schema-parser-error-msg branch from 9aa0a2c to 10b8bb0 Compare August 25, 2026 14:55
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.

6 participants