Community
Participate
Working Groups
If there is something wrong in the templates.xml file loaded by the XtextTemplateStore an IOException is logged and a message is displayed on the console. There is however no reference to any position, and with a quite generic error message it is difficult to figure out where the error is. A reference to a line number, or even "byte" would have been very helpful.
Michael Clay told me that the IOException is thrown by org.eclipse.jface.text.templates.persistence.TemplateReaderWriter.read(InputSource, ResourceBundle, String). So I consider this a Jface issue (not sure whether Platform/UI is the correct bugzilla component).
(In reply to comment #1) > Michael Clay told me that the IOException is thrown by > org.eclipse.jface.text.templates.persistence.TemplateReaderWriter.read(InputSource, > ResourceBundle, String). > > So I consider this a Jface issue (not sure whether Platform/UI is the correct > bugzilla component). For future reference, JFace Text code is owned by Platform/Text.
That's the message we get from the XML parser.
(In reply to comment #3) > That's the message we get from the XML parser. + SAXParseException (extends SAXException) will tell you the missing line and col info. pls. see o.e.j.text.templates.persistence.TemplateReaderWriter#210 catch (SAXException e) { Throwable t= e.getCause(); if (t instanceof IOException) throw (IOException) t; else if (t != null) throw new IOException(t.getMessage()); else throw new IOException(e.getMessage()); }
>+ SAXParseException (extends SAXException) will tell you the missing line and >col info. Well, I know that ;-) My point was, that the message provided by the exception does not contain the information, but it should in my opinion. If we fix this on our side then we should also include the file name in the log message.
(In reply to comment #5) > >+ SAXParseException (extends SAXException) will tell you the missing line and > >col info. > Well, I know that ;-) My point was, that the message provided by the exception > does not contain the information, but it should in my opinion. > > If we fix this on our side then we should also include the file name in the log > message. good point! the more info the better..
Created attachment 208855 [details] Proposed patch for the bug. Hi all, I'm sending a proposed patch for this bug. To address the issue, I have added an extra check to determine whether a caught exception is of a SAXParseException type which is the only subclass of SAXException that brings the asked information (a file name and a position of invalid xml fragment). If that's the case, we call toString method on it, to serialize all the neccessary information - file name, line and column numbers. Afterwards, we use the returned string to create a new IOException. So that now, if we try to read an invalid xml, we get the following: java.io.IOException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 302; The end-tag for element type "template" must end with a '>' delimiter. at org.eclipse.jface.text.templates.persistence.TemplateReaderWriter.read(TemplateReaderWriter.java:224) ... instead of just: java.io.IOException: The end-tag for element type "template" must end with a '>' delimiter. at org.eclipse.jface.text.templates.persistence.TemplateReaderWriter.read(TemplateReaderWriter.java:219) ...
Thanks for the patch Jan. The whole error handling code there is bogus. It can simply be replaced with a one-liner: throw (IOException)new IOException("Could not read template file").initCause(e); Fixed in master: 379916cd65ee970ceeb38572ad82a14ce795177c > If we fix this on our side then we should also include the file name in the > log message. This would mean too many changes for too little value.
Hi Dani. Thanks for the feedback. True, now it looks more neat.