google / cap-library

Common Alerting Protocol Library
Apache License 2.0
84 stars 26 forks source link

Off-by-one tag in error message #45

Open sschiavoni opened 9 years ago

sschiavoni commented 9 years ago

Original issue 46 created by shakusa@google.com on 2013-11-23T14:59:24.000Z:

When I try to publish this:

<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href='https://alerts.weather.gov/cap/capatomproduct.xsl' type='text/xsl'?> <!-- This atom/xml feed is an index to active advisories, watches and warnings issued by the National Weather Service. This index file is not the complete Common Alerting Protocol (CAP) alert message. To obtain the complete CAP alert, please follow the links for each entry in this index. Also note the CAP message uses a style sheet to convey the information in a human readable format. Please view the source of the CAP message to see the complete data set. Not all information in the CAP message is contained in this index of active alerts. --> <alert xmlns="urn:oasis:names:tc:emergency:cap:1.1"> <!-- http-date = Sat, 11 May 2013 05:53:00 GMT --> <identifier>NOAA-NWS-ALERTS-TX124EFFF5E9C4.TornadoWarning.124EFFF607D8TX.BROTORBRO.fca75c3d7c443bae5eba79924b439163TEST2</identifier> <sender>w-nws.webmaster@noaa.gov</sender> <sent>2013-05-19T18:53:00-05:00</sent> <status>Actual</status> <msgType>Alert</msgType> <scope>Public</scope> <note>Alert for Zapata (Texas) Issued by the National Weather Service</note> <info> <category>Met</category> <event>Tornado Warning</event> <urgency>Immediate</urgency> <severity>Extreme</severity> <certainty/> <eventCode> <valueName>SAME</valueName> <value>TOR</value> </eventCode> <effective>2013-05-19T18:53:00-05:00</effective> <expires>2013-05-19T18:30:00-05:00</expires> <senderName>NWS Brownsville (Southern Texas)</senderName> <headline>Tornado Warning issued May 11 at 12:53AM CDT until May 11 at 1:30AM CDT by NWS Brownsville</headline> <description>THE NATIONAL WEATHER SERVICE IN BROWNSVILLE HAS ISSUED A

the error says: Publisher ID:Publish[com.google.publicalerts.ingest.server.publish.AlertParseException: [noaa]com.google.publicalerts.cap.CapException: CapExceptionreasons=[Invalid enum value <severity> = "". Must be one of [Observed, Likely, Possible, Unlikely, Unknown]]]

but the error is with the certainty field, not severity.

sschiavoni commented 9 years ago

Comment #1 originally posted by sschiavoni@google.com on 2014-03-26T14:23:00.000Z:

Fixing this is quite painful, because of an unfortunate design decision in ContentHandler and ErrorHandler.

When the empty tag is parsed, CapXmlHandler.error() is triggered with the following exception (which does not contain the tag name):

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 608; cvc-enumeration-valid: Value '' is not facet-valid with respect to enumeration '[Observed, Likely, Possible, Unlikely, Unknown]'. It must be a value from the enumeration.

CapXmlHandler.startElement() is never triggered, making it impossible for us to annotate the name of the tag being parsed.

Later on, CapXmlHandler.error() is called again with the following exception (which now contains the tag name):

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 608; cvc-type.3.1.3: The value '' of element 'certainty' is not valid.

The code currently implemented in XercesCapExceptionMapper ignores the second exception.

The only solution I see to solve this issue is to change the code to allow for multiple exceptions to be associated to the same error (maybe identified with lineNumber + columNumber?), so that we can combine them to produce a better error message. Unfortunately, this looks quite ugly, and may not work at all for different types of errors.

Ideas?