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 message for generic parsing exceptions #4408

Merged
merged 2 commits into from
Mar 26, 2024

Conversation

jelovirt
Copy link
Member

@jelovirt jelovirt commented Feb 16, 2024

Description

When the input XML is in some way invalid but it can still be parsed, for example

<topic id="%50">

the XML parser will throw an exception with message

Attribute value "%50" of type ID must be an NCName when namespaces are enabled.

We currently capture this and log out as an error message.

In order to give as many messages an ID as possible, we add a message ID for generic parsing errors where the <reason> of the message is provided by the XML parser and the <response> is left empty. The logged message will be

Error: file:/Volumes/tmp/src/topic.dita:3:17: [DOTJ088E] Attribute value "%50" of type ID must be an NCName when namespaces are enabled.

or for example with incorrect attribute name that goes against the DTD

Error: file:/Volumes/tmp/src/topic.dita:3:36: [DOTJ088E] Attribute "xml:langx" must be declared for element type "topic".

Motivation and Context

Add error ID for parsing exceptions to improve debugging.

How Has This Been Tested?

Manual testing.

Type of Changes

  • New feature (non-breaking change which adds functionality)

Documentation and Compatibility

This is a generic error message, so we don't know in advance what the error message will be. Users may override the message configuration to be e.g.

<reason>Error in parsing file: %1</reason>

if they want to add more context to the message.

@jelovirt jelovirt added the feature New feature or request label Feb 16, 2024
@jelovirt jelovirt force-pushed the feature/sax-parsing-exception-message branch 2 times, most recently from d4a7f82 to 7e40c5a Compare February 16, 2024 12:14
@chrispy-snps
Copy link
Contributor

@jelovirt - this is a nice enhancement, especially now being able to override this class of message as desired.

Comment on lines 454 to 455
<reason>%1</reason>
<response></response>
Copy link
Member

Choose a reason for hiding this comment

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

If we know this is an XML parsing error, should we say so?

Suggested change
<reason>%1</reason>
<response></response>
<reason>XML parsing error: </reason>
<response>%1</response>

Copy link
Member Author

@jelovirt jelovirt Feb 25, 2024

Choose a reason for hiding this comment

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

The %1 in this case is the error message thrown by the XML parser. It describes what the error condition is, like "Attribute value "%50" of type ID must be an NCName when namespaces are enabled.".

This means it's not a response that describes what the user should do next. Because this is a generic parsing, we don't know what the next step should be. It could be "fix your specialization" or "fix your content".

This error message has been thrown before, just without any message ID. This allows us to make it easier for users to locate a description of this generic error in the message reference. There we can describe that there was something wrong with your DITA file, check that; or, if you're using a custom specialization, there may be some issue there.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so we leave the placeholder in the <reason> element, but shall we add the intro for context:

Suggested change
<reason>%1</reason>
<response></response>
<reason>XML parsing error: %1</reason>
<response></response>

Copy link
Member Author

Choose a reason for hiding this comment

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

I would prefer to not use a prefix in the reason, but it may be useful for users 🤷🏽. I'll need to get more examples of those messages to help in deciding whether it's helpful of not.

Copy link
Member Author

@jelovirt jelovirt Mar 26, 2024

Choose a reason for hiding this comment

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

Xerces produces error messages listed at https://github.com/apache/xerces2-j/blob/trunk/src/org/apache/xerces/impl/msg/XMLMessages.properties#L230. The messages are in sentence format.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added XML parsing error: prefix to the message.

@jelovirt jelovirt force-pushed the feature/sax-parsing-exception-message branch from 7e40c5a to a74d0e8 Compare March 17, 2024 06:23
@jelovirt jelovirt force-pushed the feature/sax-parsing-exception-message branch from a74d0e8 to 8a66297 Compare March 24, 2024 10:39
Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
@jelovirt jelovirt force-pushed the feature/sax-parsing-exception-message branch from 8a66297 to 37d8dc3 Compare March 26, 2024 10:46
@jelovirt jelovirt merged commit 6872d71 into develop Mar 26, 2024
4 checks passed
@jelovirt jelovirt deleted the feature/sax-parsing-exception-message branch March 26, 2024 11:08
@jelovirt jelovirt added this to the Next milestone Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants