Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add id to arbitrary dom exceptions #1234

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/src/main/java/tc/oc/pgm/map/MapFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public MapContext load() throws MapException {
} catch (ModuleLoadException e) {
throw new MapException(source, info, e.getFullMessage(), e);
} catch (JDOMParseException e) {
final InvalidXMLException cause = InvalidXMLException.fromJDOM(e, source.getId());
// Set base uri so when error is displayed it shows what XML caused the issue
Document d = e.getPartialDocument();
if (d != null) d.setBaseURI(source.getId());

final InvalidXMLException cause = InvalidXMLException.fromJDOM(e);
throw new MapException(source, info, cause.getMessage(), cause);
} catch (Throwable t) {
throw new MapException(source, info, "Unhandled " + t.getClass().getName(), t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Document getDocument()
DocumentWrapper document;
try (final InputStream stream = source.getDocument()) {
document = (DocumentWrapper) DOCUMENT_FACTORY.get().build(stream);
document.setBaseURI(source.getId() + ("default".equals(variant) ? "" : "[" + variant + "]"));
document.setBaseURI(source.getId());
}

document.runWithoutVisitation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ private File getFile() throws MapMissingException {

@Override
public String getId() {
return "<" + root.getDisplayName() + ">/" + dir.toString();
String suffix = (variant != null ? "[" + variant + "]" : "");
return "<" + root.getDisplayName() + ">/" + dir.toString() + suffix;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public InvalidXMLException(String message, Attribute attribute) {
this(message, attribute, null);
}

public static InvalidXMLException fromJDOM(JDOMParseException e, String documentPath) {
public static InvalidXMLException fromJDOM(JDOMParseException e) {
return new InvalidXMLException(
e.getMessage(),
null,
Expand Down