Skip to content

panic while printing panic value: type gojq.Operator #272

Closed
@ceving

Description

@ceving

I would like to dump jq.Query:

package main

import (
	"fmt"
	"log"
	jq "github.com/itchyny/gojq"
	"os"
)

func ReadJsonQueryFile(fname string) (*jq.Query, error) {
	data, err := os.ReadFile(fname)
	if err != nil {
		return nil, fmt.Errorf("Can not read JSON query file %q", fname, err)
	}
	query, err := jq.Parse(string(data))
	if err != nil {
		return nil, fmt.Errorf("Can not parse JSON query file %q", fname, err)
	}
	return query, nil
}

func DumpQuery(q *jq.Query) {
	fmt.Printf("Meta: %+v\n", q.Meta)
	fmt.Printf("Imports: %+v\n", q.Imports)
	fmt.Printf("FuncDefs: %+v\n", q.FuncDefs)
	fmt.Printf("Term: %+v\n", q.Term)
	fmt.Printf("Left: %+v\n", q.Left)
	fmt.Printf("Op: %+v\n", q.Op)
	fmt.Printf("Right: %+v\n", q.Right)
	fmt.Printf("Func: %+v\n", q.Func)
}

func main() {
	q, err := ReadJsonQueryFile(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	DumpQuery(q)
}

When I run the code, it panics:

$ go1.24.0 run jqv.go <(echo '$var')
Meta: <nil>
Imports: []
FuncDefs: []
Term: $var
Left: <nil>
fatal error: panic while printing panic value: type gojq.Operator

I think it should not do that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions