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

String format query with no operator using %#v or %#+v panics #56

Closed
wader opened this issue Dec 30, 2020 · 2 comments
Closed

String format query with no operator using %#v or %#+v panics #56

wader opened this issue Dec 30, 2020 · 2 comments

Comments

@wader
Copy link
Contributor

wader commented Dec 30, 2020

Hi, was digging around trying to learn more about the gojq query AST type and noticed panics for some queries when I tried to print them using log.Printf("var: %#+v\n", var) (the lv snippet in vscode). The panic happens because the expression has no operator and panics in func (Operator) String().

Example:

package main

import (
	"log"

	"github.com/itchyny/gojq"
)

func main() {
	q, err := gojq.Parse("a")
	if err != nil {
		panic(err)
	}
	log.Printf("q: %#+v\n", q)
}

Would it make sense that queries that parses successfully should be formattable like this? but I understand the panic make sense to have also. Maybe a new operator enum OpNone etc?

@itchyny
Copy link
Owner

itchyny commented Dec 30, 2020

The issue is about func (Operator) GoString(), not func (Operator) String(). Adding new operator for zero value is not a good solution as a workaround for debugging purpose.

@wader
Copy link
Contributor Author

wader commented Dec 30, 2020

Ah yes sorry wrong method. I was thinking a non-zero OpNone that the parser assigns when parsing.

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

No branches or pull requests

2 participants