diff --git a/README.md b/README.md index b9a1788..6cc05ca 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ dependencies { ## What's New +* **0.7.1** Adding some parser exception safety and added slf4j dependency for logging errors * **0.7.0** Adding some null safety on some of the base functions * **0.6.9** Fixed some null pointer issues if content on base64encode was null and some exceptions on array traversal * **0.6.8** Fixed ! (not) operator and added base64encode, base64decode, textdecodebase64, textencodebase64 diff --git a/build.gradle b/build.gradle index 6006925..6c7e504 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ ext { group = 'com.bertramlabs.plugins' -version = '0.7.0' +version = '0.7.1' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") sourceCompatibility = "1.8" @@ -46,11 +46,14 @@ dependencies { api 'com.fasterxml.jackson.core:jackson-databind:2.14.1' api 'com.fasterxml.jackson.core:jackson-annotations:2.14.1' api 'com.fasterxml.jackson.core:jackson-core:2.14.1' + api "org.slf4j:slf4j-parent:1.7.26" + api "org.slf4j:slf4j-api:1.7.26" testImplementation platform("org.spockframework:spock-bom:2.3-groovy-4.0") testImplementation "org.spockframework:spock-core" testImplementation "org.spockframework:spock-junit4" // you can remove this if your code does not rely on old JUnit 4 rules testImplementation "org.apache.groovy:groovy-all:4.0.4" + // testImplementation "org.spockframework:spock-core:2.3-groovy-3.0" } diff --git a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java index c9040b0..7513a41 100644 --- a/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java +++ b/src/main/java/com/bertramlabs/plugins/hcl4j/HCLParser.java @@ -21,6 +21,8 @@ import java.io.*; import java.nio.charset.Charset; import java.util.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Parser for the Hashicorp Configuration Language (HCL). This is the primary endpoint and converts the HCL syntax into a {@link Map}. @@ -41,7 +43,7 @@ * @author David Estes */ public class HCLParser { - + static Logger log = LoggerFactory.getLogger(HCLParser.class); //Time to parse the AST Tree into a Map protected Map result = new LinkedHashMap<>(); protected Map variables = new LinkedHashMap<>(); @@ -296,33 +298,28 @@ public Map parse(Reader reader) throws HCLParserException, IOExce public Map parse(Reader reader, Boolean ignoreParserExceptions) throws HCLParserException, IOException { HCLLexer lexer = new HCLLexer(reader); ArrayList rootBlocks; - - if(ignoreParserExceptions) { - try { - lexer.yylex(); - } catch(Exception ex) { - //TODO: Log the exception - } - } else { - lexer.yylex(); - } - - - rootBlocks = lexer.elementStack; + try { + lexer.yylex(); + rootBlocks = lexer.elementStack; - result = new LinkedHashMap<>(); - Map mapPosition = result; + result = new LinkedHashMap<>(); + Map mapPosition = result; - for(Symbol currentElement : rootBlocks) { - processSymbolPass1(currentElement,mapPosition); - } + for(Symbol currentElement : rootBlocks) { + processSymbolPass1(currentElement,mapPosition); + } - //pass2 - for(String key : result.keySet()) { + //pass2 + for(String key : result.keySet()) { processSymbolPass2(result.get(key),result); + } + } catch(Exception ex) { + log.error("Error Parsing HCL...{}",ex.getMessage(),ex); + if(ignoreParserExceptions != true) { //its nullable so thats why we look at inverse + throw new RuntimeException(ex); + } } -// System.out.println(result); return result; }