Open
Description
Describe the bug
I know the issue here is obvious and human error;
"path", .path
in the last object definition
which should have been:
"path": .path
But I still believe this should be handled, instead of panic.
Version of yq: 4.44.6
Operating system: Linux/openSUSE Tumbleweed 20250710
Installed via: zypper, OSS repo
Input Yaml
---
modules:
- name: test1
sources:
- type: file
path: files/0
sha256: aaaaa
Command
The command you ran:
yq --unwrapScalar --nul-output --no-colors \
'... comments="" |
.modules[] |
.name as $modname |
.sources[] |
select(has("sha256")) |
{"module": $modname, "url": .url, "path", .path, "sha256": .sha256}[]' "test.yaml"
Actual behavior
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/mikefarah/yq/v4/pkg/yqlib.collectObjectOperator(0x55e9229bd000, {0xc000319770, 0xc000319980, 0x0, {0x0, 0x0}}, 0x1?)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_collect_object.go:39 +0xcd0
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc000319770, 0xc000319980, 0x0, {0x0, 0x0}}, 0xc0000127b0)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0x55e9229bd000, {0xc00030d380, 0xc00030dd40, 0x0, {0x0, 0x0}}, 0xc0000127c8)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:13 +0x1a8
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc00030d380, 0xc00030dd40, 0x0, {0x0, 0x0}}, 0xc0000127c8)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.traverseArrayOperator(0x55e9229bd000, {0xc00030d380, 0xc00030dd40, 0x0, {0x0, 0x0}}, 0xc000012810)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_traverse_path.go:83 +0x1c7
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc00030d380, 0xc00030dd40, 0x0, {0x0, 0x0}}, 0xc000012810)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0x55e9229bd000, {0xc00030d0b0, 0xc00030d2f0, 0x0, {0x0, 0x0}}, 0xc000012828)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:13 +0x1a8
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc00030d0b0, 0xc00030d2f0, 0x0, {0x0, 0x0}}, 0xc000012828)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0x55e9229bd000, {0xc00030c990, 0xc00030cc30, 0x0, {0x0, 0x0}}, 0xc000012840)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:13 +0x1a8
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc00030c990, 0xc00030cc30, 0x0, {0x0, 0x0}}, 0xc000012840)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.variableLoopSingleChild(0x55e9229bd000, {0xc00030c990, 0xc00030c9f0, 0x0, {0x0, 0x0}}, 0xc000012858)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_variables.go:81 +0x78c
github.com/mikefarah/yq/v4/pkg/yqlib.variableLoop(0x55e9229bd000, {0xc00030c810, 0xc00030c930, 0x0, {0x0, 0x0}}, 0xc000012858)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_variables.go:43 +0x32b
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0xc0000b48c0?, {0xc00030c810, 0xc00030c930, 0x0, {0x0, 0x0}}, 0x1?)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:6 +0x319
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc00030c810, 0xc00030c930, 0x0, {0x0, 0x0}}, 0xc000012858)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0x55e9229bd000, {0xc0002f6ba0, 0xc00030c510, 0x0, {0x0, 0x0}}, 0xc000012870)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:13 +0x1a8
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc0002f6ba0, 0xc00030c510, 0x0, {0x0, 0x0}}, 0xc000012870)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.pipeOperator(0x55e9229bd000, {0xc0002f6ba0, 0x0, 0x0, {0x0, 0x0}}, 0xc000012888)
github.com/mikefarah/yq/v4/pkg/yqlib/operator_pipe.go:13 +0x1a8
github.com/mikefarah/yq/v4/pkg/yqlib.(*dataTreeNavigator).GetMatchingNodes(0x55e9229bd000, {0xc0002f6ba0, 0x0, 0x0, {0x0, 0x0}}, 0xc000012888)
github.com/mikefarah/yq/v4/pkg/yqlib/data_tree_navigator.go:65 +0x21f
github.com/mikefarah/yq/v4/pkg/yqlib.(*streamEvaluator).Evaluate(0xc000047bb8, {0x7ffd0a5eba90, 0x9}, {0x55e9225bf888?, 0xc0000246c0?}, 0xc000012888, {0x55e9225c2540, 0xc0002dbab0}, {0x55e9225c06a0, 0xc0002dbb20})
github.com/mikefarah/yq/v4/pkg/yqlib/stream_evaluator.go:101 +0x2cc
github.com/mikefarah/yq/v4/pkg/yqlib.(*streamEvaluator).EvaluateFiles(0xc000047bb8, {0x7ffd0a5eb9de, 0xb1}, {0xc0000be510, 0x1, 0xc000047968?}, {0x55e9225c2540, 0xc0002dbab0}, {0x55e9225c06a0, 0xc0002dbb20})
github.com/mikefarah/yq/v4/pkg/yqlib/stream_evaluator.go:58 +0x158
github.com/mikefarah/yq/v4/cmd.evaluateSequence(0xc000246308, {0xc0000be500, 0x2, 0x5})
github.com/mikefarah/yq/v4/cmd/evaluate_sequence_command.go:144 +0x885
github.com/spf13/cobra.(*Command).execute(0xc000246308, {0xc0000be4b0, 0x5, 0x5})
github.com/spf13/[email protected]/command.go:985 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc000246008)
github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0xc000042720?)
github.com/spf13/[email protected]/command.go:1041 +0x13
main.main()
github.com/mikefarah/yq/v4/yq.go:22 +0x1a8
Expected behavior
Printed error-message about syntax error.
Additional context
Add any other context about the problem here.