Update on my technical exploration:
After diving deeper into the codebase, I want to share my refined understanding.
What I found in ConfigParser.cpp:
The xmlParserCtxtPtr (_context) is stored as a member of ConfigParser. During SAX callbacks like startElement(), calling xmlGetLineNumber(_context) returns a valid line number. The issue is that this context pointer never reaches the XMLTag handlers — so by the time an error is thrown in configuration code, the location is already gone.
My proposed fix — capture location at parse time:
cpp
struct XMLLocation {
int line = 0;
int column = 0;
std::string file;
};
Inside ConfigParser::startElement(), right when the tag is identified, store the location into the tag before passing it to handlers:
cpp
tag.setLocation(
xmlGetLineNumber(_context),
xmlGetColumnNo(_context),
_filename
);
Then error messages become:
cpp
auto loc = tag.location();
PRECICE_ERROR("Unknown tag <{}> at {}:{}",
tag.getName(), loc.line, loc.column);
```
**Open questions I want to verify with maintainers:**
- Is `xmlGetColumnNo` reliable across all libxml2 versions preCICE supports?
- Should location be stored per-attribute separately, or is tag-level location enough?
Would love feedback before I start prototyping.
---
**Paste karne ke baad yeh check karo:**
Discourse mein **Preview** tab hoga right side pe — wahan code blocks green/grey background mein dikhne chahiye aisi:
```
struct XMLLocation {
Update — Initial Implementation Pushed to Fork
I have pushed an initial implementation to my fork: https://github.com/SKM2227229725/precice/tree/feature/xml-error-context
Changes so far:
-
Added m_Line, m_Column, m_File fields to CTag struct
-
Stored _parserContext as member of ConfigParser
-
Captured location in OnStartElement() while context is valid
-
Saved file content as _fileLines for context display
Next step: Propagate from CTag → XMLTag to expose clean APIs:
cpp
tag.location()
tag.attributeLocation(ATTR_NAME)
```
So error messages look like:
```
ERROR: Data was defined with an empty name.
2: <data:scalar name="" />
^^^^^^^