perfectsense / gyro

Gyro is a command-line tool for creating, updating, and maintaining cloud infrastructure. Gyro makes infrastructure-as-code possible.
https://gyro.dev
Apache License 2.0
134 stars 7 forks source link

Catch class cast exception during parsing #388

Closed beetlebugorg closed 2 years ago

beetlebugorg commented 2 years ago

One place this can happen is when a reference resolver that expects a map is used but the plugin that defines the resolver isn't loaded.

Example:

@print: $(custom::resolver "abc" {
    "a": "b"
})

This will result in:

Caused by: Unexpected error: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')
    at gyro.core.scope.NodeEvaluator.lambda$visitReference$41(NodeEvaluator.java:717)

With this code change it'll result in:

Error: Can't process the @print directive!

In test.gyro from line 2 at column 1 to line 4 at column 2:
2: @print: $(custom::resolver "abc" { 
3:     "a": "b"
4: })

Caused by: Error: Can't resolve custom::resolver reference!

In test.gyro from line 2 at column 9 to line 4 at column 2:
2: @print: $(custom::resolver "abc" { 
3:     "a": "b"
4: })

Caused by: Unexpected error: java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap')