Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 321664 - [templates] IOException while loading templates.xml should indicate position
Summary: [templates] IOException while loading templates.xml should indicate position
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P5 minor (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-03 23:09 EDT by Henrik Lindberg CLA
Modified: 2012-01-11 16:37 EST (History)
5 users (show)

See Also:


Attachments
Proposed patch for the bug. (1.22 KB, patch)
2011-12-29 11:45 EST, Jan Opacki CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Lindberg CLA 2010-08-03 23:09:59 EDT
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.
Comment 1 Sven Efftinge CLA 2010-08-11 10:24:40 EDT
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).
Comment 2 Remy Suen CLA 2010-08-11 10:31:54 EDT
(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.
Comment 3 Dani Megert CLA 2010-08-11 11:25:02 EDT
That's the message we get from the XML parser.
Comment 4 Michael Clay CLA 2010-08-11 15:55:36 EDT
(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());
		}
Comment 5 Dani Megert CLA 2010-08-12 04:08:46 EDT
>+ 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.
Comment 6 Michael Clay CLA 2010-08-12 05:04:57 EDT
(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..
Comment 7 Jan Opacki CLA 2011-12-29 11:45:56 EST
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)
...
Comment 8 Dani Megert CLA 2012-01-10 06:25:33 EST
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.
Comment 9 Jan Opacki CLA 2012-01-11 16:37:31 EST
Hi Dani. Thanks for the feedback. True, now it looks more neat.