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

The program crashes with the error "panic: runtime error: index out of range" #1184

Closed
SokoloffA opened this issue Apr 15, 2022 · 6 comments
Closed
Labels

Comments

@SokoloffA
Copy link

Describe the bug
The program crashes with the error "panic: runtime error: index out of range"

Version of yq: 4.25.5
Operating system: linux
Installed via: binary release

Input Yaml
data1.yml:

_common: &common-docker-file
  - FROM ubuntu:18.04

steps:
  - dockerfile:
     <<: *common-docker-file

Command
The command you ran:

yq eval ".steps.[].dockerfile.[]"  data1.yml

Actual behavior

panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/mikefarah/yq/v4/pkg/yqlib.doTraverseMap(0xc0004662d0?, 0xc000462460, {0x0, 0x0}, {0x0, 0x0, 0x0, 0x0, 0x0}, 0x1)
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:280 +0xa25
github.com/mikefarah/yq/v4/pkg/yqlib.traverseMergeAnchor(0x5?, 0xc000462380, 0xc?, {0x0, 0x0}, {0x0, 0x0, 0x0, 0x0, 0x0}, ...)
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:313 +0x22d
github.com/mikefarah/yq/v4/pkg/yqlib.doTraverseMap(0x1?, 0xc000462380, {0x0, 0x0}, {0x0, 0x0, 0x0, 0x0, 0x0}, 0x1)
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:286 +0x293
github.com/mikefarah/yq/v4/pkg/yqlib.traverseMap({0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, 0xc000462380, {0x0, 0x0}, {0x0, 0x0, ...}, ...)
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:229 +0x133
github.com/mikefarah/yq/v4/pkg/yqlib.traverseMapWithIndices({0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, 0x30?, {0x0?, 0xc000466240?, 0x0?}, {0x0, ...})
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:158 +0xef
github.com/mikefarah/yq/v4/pkg/yqlib.traverseArrayIndices({0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, 0xc000462380, {0x0, 0x0, 0x0}, {0x0, ...})
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:148 +0x4d2
github.com/mikefarah/yq/v4/pkg/yqlib.traverseNodesWithArrayIndices({0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, {0x0, 0x0, 0x0}, {0x0, 0x0, ...})
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:116 +0x173
github.com/mikefarah/yq/v4/pkg/yqlib.traverseArrayOperator(0xc000123800?, {0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, 0xc0003f4468)
        /home/runner/work/yq/yq/pkg/yqlib/operator_traverse_path.go:105 +0x378
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x0?, {0xc000377c80, 0xc000377e30, 0x0, {0x0, 0x0}}, 0xc0003f4468)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x25c
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0xc000123800?, {0xc000377b00, 0xc000377c50, 0x0, {0x0, 0x0}}, 0xc0003f4480)
        /home/runner/work/yq/yq/pkg/yqlib/operator_pipe.go:13 +0x147
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x0?, {0xc000377b00, 0xc000377c50, 0x0, {0x0, 0x0}}, 0xc0003f4480)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x25c
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0xc000123800?, {0xc000377530, 0xc0003776b0, 0x0, {0x0, 0x0}}, 0xc0003f4498)
        /home/runner/work/yq/yq/pkg/yqlib/operator_pipe.go:13 +0x147
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x46af9e?, {0xc000377530, 0xc0003776b0, 0x0, {0x0, 0x0}}, 0xc0003f4498)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x25c
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0xc000123800?, {0xc0003774d0, 0x0, 0x0, {0x0, 0x0}}, 0xc0003f44b0)
        /home/runner/work/yq/yq/pkg/yqlib/operator_pipe.go:13 +0x147
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x0?, {0xc0003774d0, 0x0, 0x0, {0x0, 0x0}}, 0xc0003f44b0)
        /home/runner/work/yq/yq/pkg/yqlib/data_tree_navigator.go:37 +0x25c
github.com/mikefarah/yq/v4/pkg/yqlib.(*streamEvaluator).Evaluate(0xc000449cf0, {0x7fff089c60b2, 0x9}, {0x837120?, 0xc000404300?}, 0x745c40?, {0x838cb0, 0xc0004041e0}, {0x0, 0x0}, ...)
        /home/runner/work/yq/yq/pkg/yqlib/stream_evaluator.go:119 +0x310
github.com/mikefarah/yq/v4/pkg/yqlib.(*streamEvaluator).EvaluateFiles(0xc000128008?, {0x7fff089c609a, 0x17}, {0xc000146630, 0x1, 0xc000144f8c?}, {0x838cb0, 0xc0004041e0}, 0x54?, {0x838220, ...})
        /home/runner/work/yq/yq/pkg/yqlib/stream_evaluator.go:73 +0x30e
github.com/mikefarah/yq/v4/cmd.evaluateSequence(0xc00014d400?, {0xc000146620?, 0x2, 0x2})
        /home/runner/work/yq/yq/cmd/evalute_sequence_command.go:160 +0x1325
github.com/spf13/cobra.(*Command).execute(0xc00014d400, {0xc0001465c0, 0x2, 0x2})
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0xc00014d180)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902
main.main()
        /home/runner/work/yq/yq/yq.go:22 +0x1f1

Expected behavior

FROM ubuntu:18.04
@mikefarah
Copy link
Owner

It shouldn't stack error like that (which is a bug) - but the issue is that it isn't valid yaml. The merge anchor <<: (afaik) is only applicable to maps - not arrays.

If you have:

_common: &common-docker-file
  - FROM ubuntu:18.04

steps:
  - dockerfile: *common-docker-file

then it works

@mikefarah
Copy link
Owner

@SokoloffA
Copy link
Author

Thank you, I suspected that my YAML isn't valid. I was confused that several online validators accepted my YAML.

Thank you for the excellent program!

@mikefarah
Copy link
Owner

mikefarah commented Apr 16, 2022 via email

@mikefarah mikefarah reopened this Apr 16, 2022
@mikefarah
Copy link
Owner

Accidentally closed - I need to handle the panic error into a more friendly message

@mikefarah
Copy link
Owner

Fixed in 4.25.1

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

No branches or pull requests

2 participants