Menu

#3 Exception when file mismatches schema

open
None
3
2004-12-08
2004-11-23
Tim Booth
No

If I start Pedro with one model loaded and try to load
a document created with a different schema I get a big
SAXException.

Pedro should ideally load the correct schema and show
the file, but at least there should be an error message
displayed - the only feedback right now is the
exception trace - ie:

org.xml.sax.SAXException: Experiment file uses schema
"/home/user4/pedro1-3/dist/models/metadata/model/Metadata.xsd"
but the application is using schema
"/home/tbooth/tings/pedro17/dist/models/pedro/model/PEDRoSchema.xsd"
at
pedro.io.PedroDataFileReader.verifySchemaInformation(PedroDataFileReader.java:345)
at
pedro.io.PedroDataFileReader.startElement(PedroDataFileReader.java:428)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:798)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:1157)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at
javax.xml.parsers.SAXParser.parse(SAXParser.java:375)
at
javax.xml.parsers.SAXParser.parse(SAXParser.java:176)
at
pedro.io.NativeFileFormatReader.parseNativeFormatFile(NativeFileFormatReader.java:146)
at
pedro.io.NativeFileFormatReader.readFile(NativeFileFormatReader.java:105)
at pedro.FileMenu.openFile(FileMenu.java:608)
at pedro.FileMenu.open(FileMenu.java:408)
at
pedro.FileMenu.actionPerformed(FileMenu.java:1333)

...etc...

Discussion

  • Kevin Garwood

    Kevin Garwood - 2004-12-08
    • priority: 5 --> 3
    • assigned_to: nobody --> kgarwood
     
  • Tim Booth

    Tim Booth - 2005-04-25

    Logged In: YES
    user_id=1164653

    This from tim_changelog.txt

    25/4/05:
    In response to Kev:

    > the main pedro io readers use SAX -- and I'm having trouble
    > getting exceptions I throw in the code to show up in the
    error dialog
    > box. For example, if I try loading data files with an
    incompatible
    > model name stamp, I just get a blank Error dialog. I
    don't want to call
    > the error dialog from within the io routines because they
    may have to be
    > used in a setting that doesn't use a UI. Thoughts?

    I did some tracing and found the following:

    A) Loading a file with the wrong model yields an error message.
    B) Having the wrong document element dumps an exception but
    there is no error.

    A) The error actually comes from
    MetaDataReader.fileUsesCurrentSchema
    This calls addError directly even though it is not UI code

    The trap at FileMenu.openFile is a good place to handle
    all the errors, so
    all exceptions should end up here.

    The original error is trapped at
    PedroDataFileReader.verifySchemaInformation
    and a SAX exception is thrown. SAX catches this and
    cleans up, but then re-throws
    the exception so that it turns up in
    NativeFileFormatReader.parseNativeFormatFile.
    At this point a stack trace is printed and code continues.

    Changes made:

    Modified the handler in
    NativeFileFormatReader.parseNativeFormatFile to re-throw
    the exception (converted to a PedroException). Small change.

    Modified MetaDataReader.fileUsesCurrentSchema and made
    MetaDataReader.checkFileUsesCurrentSchema which throws
    PedroExceptions rather than returning
    false on error. These exceptions also end up in the
    FileMenu.openFile trap. Bigger change.

    Kev will check on Wednesday - there may be more to do.

     

Log in to post a comment.

MongoDB Logo MongoDB