Skip to content
This repository has been archived by the owner on Oct 25, 2020. It is now read-only.

panic: didn't find any token of type TokenOBrack #5

Closed
pdecat opened this issue Dec 6, 2019 · 1 comment · Fixed by #11
Closed

panic: didn't find any token of type TokenOBrack #5

pdecat opened this issue Dec 6, 2019 · 1 comment · Fixed by #11

Comments

@pdecat
Copy link
Contributor

pdecat commented Dec 6, 2019

On the heels of #2, here's a variant with TokenOBrack:

# terraform-clean-syntax common/k8s/cluster0/monitoring.tf
panic: didn't find any token of type TokenOBrack

goroutine 1 [running]:
github.com/hashicorp/hcl/v2/hclwrite.inputTokens.PartitionType(0xc0000f7ce0, 0x2, 0x2, 0xc0000ba698, 0x2, 0x2, 0x7fff0000005b, 0x0, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:88 +0x580
github.com/hashicorp/hcl/v2/hclwrite.parseTraversalStep(0x709100, 0xc0000b0f60, 0xc0000f7ce0, 0x2, 0x2, 0xc0000ba698, 0x2, 0x2, 0xc0000f7ce0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:408 +0xdab
github.com/hashicorp/hcl/v2/hclwrite.parseTraversal(0xc0000f0100, 0x5, 0x8, 0xc0000f7b00, 0x9, 0x9, 0xc0000ba670, 0x9, 0x9, 0xc0000f7b00, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:377 +0x3da
github.com/hashicorp/hcl/v2/hclwrite.parseExpression(0x70a740, 0xc0000b0d80, 0xc0000f7b00, 0x9, 0x9, 0xc0000ba670, 0x9, 0x9, 0x2)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:356 +0x175
github.com/hashicorp/hcl/v2/hclwrite.parseAttribute(0xc0000d01c0, 0xc0000f7b00, 0x0, 0x0, 0xc0000ba670, 0x0, 0x0, 0xc0000f79e0, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:260 +0xaf4
github.com/hashicorp/hcl/v2/hclwrite.parseBodyItem(0x707960, 0xc0000d01c0, 0xc0000f79e0, 0xd, 0xd, 0xc0000ba658, 0xd, 0xd, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:217 +0x632
github.com/hashicorp/hcl/v2/hclwrite.parseBody(0xc0000ba4d0, 0xc0000f79e0, 0xd, 0xd, 0xc0000ba658, 0xd, 0xd, 0x0, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:193 +0x68d
github.com/hashicorp/hcl/v2/hclwrite.parseBlock(0xc0000b67e0, 0xc0000f79e0, 0x0, 0x0, 0xc0000ba658, 0x0, 0x0, 0xc0000f7800, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:329 +0xf72
github.com/hashicorp/hcl/v2/hclwrite.parseBodyItem(0x7079a0, 0xc0000b67e0, 0xc0000f7800, 0x14, 0x14, 0xc0000ba630, 0x14, 0x14, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:219 +0x4f7
github.com/hashicorp/hcl/v2/hclwrite.parseBody(0xc0000ba580, 0xc0000f7800, 0x15, 0x20, 0xc0000ba630, 0x15, 0x15, 0x0, 0x0, 0x0, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:193 +0x68d
github.com/hashicorp/hcl/v2/hclwrite.parse(0xc000104000, 0x4e, 0x24e, 0x7fff989f6e41, 0x21, 0x1, 0x1, 0x0, 0xffffffffffffff9c, 0xc0000a8210, ...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/parser.go:53 +0x2e4
github.com/hashicorp/hcl/v2/hclwrite.ParseConfig(...)
        /home/patrick/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0/hclwrite/public.go:27
main.processFile(0x7fff989f6e41, 0x21, 0x1a4)
        /home/patrick/go/src/github.com/apparentlymart/terraform-clean-syntax/main.go:78 +0xc8
main.processItem(0x7fff989f6e41, 0x21)
        /home/patrick/go/src/github.com/apparentlymart/terraform-clean-syntax/main.go:55 +0x2e7
main.main()
        /home/patrick/go/src/github.com/apparentlymart/terraform-clean-syntax/main.go:30 +0xec

Here's the culprit:

module "test" {
  test         = kubernetes_config_map.test.metadata.0.name
}
@apparentlymart
Copy link
Owner

Oh, interesting... this one seems to be hclwrite not understanding this legacy HIL-style index syntax .0 instead of [0].

If you don't have too many examples of this and want to work around this quickly for now, I think manually rewriting that as follows should fix it:

module "test" {
  test = kubernetes_config_map.test.metadata[0].name
}

I'll make an HCL issue for this later, but hopefully that helps as a workaround in the meantime.

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

Successfully merging a pull request may close this issue.

2 participants