feat: Augment schema parser error messages - #277
Conversation
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
de693b2 to
2d2c36e
Compare
|
The fix from #276 should be merged first. |
47c5a6d to
daf484f
Compare
|
I agree that 0 rules should be an error. |
1d9d990 to
b2fd67d
Compare
b2fd67d to
6399d0d
Compare
ccfef7f to
105c185
Compare
|
ecmwf/eckit#293 needs to be merged first. |
9571e30 to
d144eea
Compare
6e4d27a to
c652f94
Compare
c652f94 to
d21aa42
Compare
d83f04f to
616d007
Compare
616d007 to
18ab945
Compare
There was a problem hiding this comment.
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::endlends up inwhat()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 withparser_.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::Errorwithout 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
SchemaParserpreviously initialised the underlyingeckit::StreamParserwith 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 usesparser_.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
constreference (no mutation intended, and it allows catching const exceptions).
catch (SchemaParser::Error& spe) {
c0fc206 to
6bb00b6
Compare
6bb00b6 to
9aa0a2c
Compare
Now showing in which step of the schema file parsing the error is occurring.
Also refactor error messages
9aa0a2c to
10b8bb0
Compare
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:
🌈🌦️📖🚧 Documentation FDB 🚧📖🌦️🌈
https://sites.ecmwf.int/docs/fdb/pull-requests/PR-277