Improved sloppy parser exception handling
This commit is contained in:
parent
2bf3860cbc
commit
e7c3276541
3 changed files with 205 additions and 174 deletions
|
@ -7,6 +7,7 @@ Changelog
|
||||||
- Fixed perpetually green "Update" button
|
- Fixed perpetually green "Update" button
|
||||||
- Added --global-panic commandline arg to show mod devs typoed find tags
|
- Added --global-panic commandline arg to show mod devs typoed find tags
|
||||||
- Added commandline tips in readme_modders.txt
|
- Added commandline tips in readme_modders.txt
|
||||||
|
- Fixed sloppy parser Validate error about things not allowed at root
|
||||||
|
|
||||||
1.2:
|
1.2:
|
||||||
- Added a commandline interface
|
- Added a commandline interface
|
||||||
|
|
|
@ -824,7 +824,7 @@ public class ModUtilities {
|
||||||
xmlValid = false;
|
xmlValid = false;
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
log.error( "Error while validating mod xml.", e );
|
log.error( "Error while validating mod xml with the strict parser.", e );
|
||||||
messages.add( new ReportMessage(
|
messages.add( new ReportMessage(
|
||||||
ReportMessage.EXCEPTION,
|
ReportMessage.EXCEPTION,
|
||||||
"An error occurred. See log for details."
|
"An error occurred. See log for details."
|
||||||
|
@ -846,6 +846,9 @@ public class ModUtilities {
|
||||||
List<ReportMessage> messages = new ArrayList<ReportMessage>();
|
List<ReportMessage> messages = new ArrayList<ReportMessage>();
|
||||||
boolean xmlValid = true;
|
boolean xmlValid = true;
|
||||||
|
|
||||||
|
// Meh, the parser's gonna make its own wrapper with declarations anyway.
|
||||||
|
//text = "<wrapper xmlns:mod='mod' xmlns:mod-append='mod-append' xmlns:mod-overwrite='mod-overwrite'>"+ text +"</wrapper>";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SloppyXMLParser parser = new SloppyXMLParser();
|
SloppyXMLParser parser = new SloppyXMLParser();
|
||||||
parser.build( text );
|
parser.build( text );
|
||||||
|
@ -876,6 +879,7 @@ public class ModUtilities {
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
log.error( "Error while validating mod xml with the sloppy parser.", e );
|
||||||
messages.add( new ReportMessage(
|
messages.add( new ReportMessage(
|
||||||
ReportMessage.EXCEPTION,
|
ReportMessage.EXCEPTION,
|
||||||
"An error occurred. See log for details."
|
"An error occurred. See log for details."
|
||||||
|
@ -883,6 +887,13 @@ public class ModUtilities {
|
||||||
}
|
}
|
||||||
xmlValid = false;
|
xmlValid = false;
|
||||||
}
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
|
log.error( "Error while validating mod xml with the sloppy parser.", e );
|
||||||
|
messages.add( new ReportMessage(
|
||||||
|
ReportMessage.EXCEPTION,
|
||||||
|
"An error occurred. See log for details."
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
return new Report( messages, xmlValid );
|
return new Report( messages, xmlValid );
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.jdom2.Content;
|
||||||
import org.jdom2.DefaultJDOMFactory;
|
import org.jdom2.DefaultJDOMFactory;
|
||||||
import org.jdom2.Document;
|
import org.jdom2.Document;
|
||||||
import org.jdom2.Element;
|
import org.jdom2.Element;
|
||||||
|
import org.jdom2.IllegalAddException;
|
||||||
import org.jdom2.JDOMFactory;
|
import org.jdom2.JDOMFactory;
|
||||||
import org.jdom2.Namespace;
|
import org.jdom2.Namespace;
|
||||||
import org.jdom2.Parent;
|
import org.jdom2.Parent;
|
||||||
|
@ -115,6 +116,7 @@ public class SloppyXMLParser {
|
||||||
String tmp = null;
|
String tmp = null;
|
||||||
Matcher m = declPtn.matcher( s );
|
Matcher m = declPtn.matcher( s );
|
||||||
|
|
||||||
|
try {
|
||||||
while ( pos > lastPos && pos < sLen ) {
|
while ( pos > lastPos && pos < sLen ) {
|
||||||
m.region( pos, sLen );
|
m.region( pos, sLen );
|
||||||
boolean matchedChunk = false;
|
boolean matchedChunk = false;
|
||||||
|
@ -309,6 +311,23 @@ public class SloppyXMLParser {
|
||||||
factory.setRoot( doc, newRoot );
|
factory.setRoot( doc, newRoot );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( IllegalAddException e ) {
|
||||||
|
int nonspacePos = findNextNonspace( s, pos );
|
||||||
|
int errorPos = ( (nonspacePos != -1) ? nonspacePos : pos );
|
||||||
|
|
||||||
|
int[] lineAndCol = getLineAndCol( s, errorPos );
|
||||||
|
int lineNum = lineAndCol[0];
|
||||||
|
int colNum = lineAndCol[1];
|
||||||
|
|
||||||
|
String hint = "";
|
||||||
|
if ( e.getMessage() != null && e.getMessage().indexOf( "not allowed at the document root" ) != -1 ) {
|
||||||
|
hint = " (There's likely an extraneous closing tag before this point.)";
|
||||||
|
}
|
||||||
|
SAXParseException cause = new SAXParseException( String.format( "At line %d, column %d: %s%s", lineNum, colNum, e.getMessage(), hint ), null, null, lineNum, colNum, e);
|
||||||
|
throw new JDOMParseException( String.format( "Error on line %d: %s", lineNum, cause.getMessage() ), cause );
|
||||||
|
}
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue