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
|
||||
- Added --global-panic commandline arg to show mod devs typoed find tags
|
||||
- Added commandline tips in readme_modders.txt
|
||||
- Fixed sloppy parser Validate error about things not allowed at root
|
||||
|
||||
1.2:
|
||||
- Added a commandline interface
|
||||
|
|
|
@ -824,7 +824,7 @@ public class ModUtilities {
|
|||
xmlValid = false;
|
||||
}
|
||||
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(
|
||||
ReportMessage.EXCEPTION,
|
||||
"An error occurred. See log for details."
|
||||
|
@ -846,6 +846,9 @@ public class ModUtilities {
|
|||
List<ReportMessage> messages = new ArrayList<ReportMessage>();
|
||||
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 {
|
||||
SloppyXMLParser parser = new SloppyXMLParser();
|
||||
parser.build( text );
|
||||
|
@ -876,6 +879,7 @@ public class ModUtilities {
|
|||
) );
|
||||
}
|
||||
else {
|
||||
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."
|
||||
|
@ -883,6 +887,13 @@ public class ModUtilities {
|
|||
}
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.jdom2.Content;
|
|||
import org.jdom2.DefaultJDOMFactory;
|
||||
import org.jdom2.Document;
|
||||
import org.jdom2.Element;
|
||||
import org.jdom2.IllegalAddException;
|
||||
import org.jdom2.JDOMFactory;
|
||||
import org.jdom2.Namespace;
|
||||
import org.jdom2.Parent;
|
||||
|
@ -115,6 +116,7 @@ public class SloppyXMLParser {
|
|||
String tmp = null;
|
||||
Matcher m = declPtn.matcher( s );
|
||||
|
||||
try {
|
||||
while ( pos > lastPos && pos < sLen ) {
|
||||
m.region( pos, sLen );
|
||||
boolean matchedChunk = false;
|
||||
|
@ -309,6 +311,23 @@ public class SloppyXMLParser {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue