Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error Parsing Numerical Value" when using a number minus something #37

Open
mccartney opened this issue Oct 16, 2023 · 2 comments
Open

Comments

@mccartney
Copy link
Contributor

The following code:

locals {
  one = 1
  two = 3 - one
}

fails with:

com.bertramlabs.plugins.hcl4j.HCLParserException: Error Parsing Numerical Value in HCL Attribute 
        at com.bertramlabs.plugins.hcl4j.HCLParser.processValue(HCLParser.java:841)
        at com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:462)
        at com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:656)
        at com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:418)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:315)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:276)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:200)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:183)
[...]
Caused by: java.lang.NumberFormatException: For input string: "-"
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
        at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
        at java.lang.Double.parseDouble(Double.java:538)
        at com.bertramlabs.plugins.hcl4j.HCLParser.processValue(HCLParser.java:838)
        ... 54 more

when running new HCLParser().parse() against it.

Using hcl4j 0.7.3

@davydotcom
Copy link
Contributor

Does this work if you treat the one as a local var ... i.e. local.one instead?

@mccartney
Copy link
Contributor Author

It fails with the same error message.

Just tried with the current master (24550a3)

	void "should handle variables referring to each other" () {
		given:
		def hcl = '''
locals {
  one = 1
  two = 3 - local.one
}
'''
		HCLParser parser = new HCLParser();
		when:
		def results  = parser.parse(hcl)
		then:
		results != null
	}

fails with:

HCLParserSpec > should handle variables referring to each other FAILED
    java.lang.RuntimeException: com.bertramlabs.plugins.hcl4j.HCLParserException: Error Parsing Numerical Value in HCL Attribute 
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:348)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:136)
        at com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:123)
        at com.bertramlabs.plugins.hcl4j.HCLParserSpec.should handle variables referring to each other(HCLParserSpec.groovy:1694)

        Caused by:
        com.bertramlabs.plugins.hcl4j.HCLParserException: Error Parsing Numerical Value in HCL Attribute 
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.processValue(HCLParser.java:960)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:508)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:702)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.processSymbolPass2(HCLParser.java:464)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.lambda$parse$1(HCLParser.java:328)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.intermediateHclParserExceptionHandling(HCLParser.java:363)
            at app//com.bertramlabs.plugins.hcl4j.HCLParser.parse(HCLParser.java:328)
            ... 3 more

            Caused by:
            java.lang.NumberFormatException: For input string: "-"
                at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
                at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
                at java.base/java.lang.Double.parseDouble(Double.java:792)
                at com.bertramlabs.plugins.hcl4j.HCLParser.processValue(HCLParser.java:957)
                ... 9 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants