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

Method invocation on nil value #1629

Open
jsumners-nr opened this issue Jul 11, 2024 · 0 comments
Open

Method invocation on nil value #1629

jsumners-nr opened this issue Jul 11, 2024 · 0 comments

Comments

@jsumners-nr
Copy link

Invoking the NRQL script:

from NodeMetadataSummary
select *

Will result in an error:

❯ ~/bin/newrelic nrql query --format Text --query _table_desc.nrql
panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface({0x0?, 0x0?, 0x1400026e008?}, 0xa0?)
	/Users/jsumners/.go/src/reflect/value.go:1501 +0xfc
reflect.Value.Interface(...)
	/Users/jsumners/.go/src/reflect/value.go:1496
github.com/newrelic/newrelic-cli/internal/output.(*Output).createTableFromMapSlice(0x140003100a0, {0x101153730, 0x1400017c5a0}, {0x100f94100?, 0x14000434660?, 0x14000634000?})
	/Users/jsumners/Projects/newrelic-cli/internal/output/text.go:170 +0x3fc
github.com/newrelic/newrelic-cli/internal/output.(*Output).renderAsTable(0x140003100a0, {0x100f94100, 0x14000434660})
	/Users/jsumners/Projects/newrelic-cli/internal/output/text.go:60 +0x220
github.com/newrelic/newrelic-cli/internal/output.(*Output).text(0x18?, {0x100f94100?, 0x14000434660?})
	/Users/jsumners/Projects/newrelic-cli/internal/output/text.go:29 +0x94
github.com/newrelic/newrelic-cli/internal/output.Print({0x100f94100?, 0x14000434660?})
	/Users/jsumners/Projects/newrelic-cli/internal/output/print.go:19 +0xf0
github.com/newrelic/newrelic-cli/internal/nrql.init.func2(0x1400033e900?, {0x100d7e1c9?, 0x4?, 0x100d7e1cd?})
	/Users/jsumners/Projects/newrelic-cli/internal/nrql/command_query.go:53 +0x1e4
github.com/spf13/cobra.(*Command).execute(0x101738120, {0x140003205c0, 0x4, 0x4})
	/Users/jsumners/go/pkg/mod/github.com/spf13/[email protected]/command.go:944 +0x63c
github.com/spf13/cobra.(*Command).ExecuteC(0x10172b500)
	/Users/jsumners/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/jsumners/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
main.Execute()
	/Users/jsumners/Projects/newrelic-cli/cmd/newrelic/command.go:74 +0x104
main.main()
	/Users/jsumners/Projects/newrelic-cli/cmd/newrelic/main.go:66 +0x1

The issue is at:

for j, k := range sortedKeys {
if key := findStringValue(k, keys); key != nil {
val := v.Index(i).MapIndex(*key)
row[j] = val.Interface()
}
}

A fix for it is:

		for j, k := range sortedKeys {
			if key := findStringValue(k, keys); key != nil {
				val := v.Index(i).MapIndex(*key)
				if !val.IsValid() {
					row[j] = ""
				} else {
					row[j] = val.Interface()
				}
			}
		}

However, that just skirts around the problem. The actual problem is that each row in the result set does not necessarily have the same number of columns. I have dealt with a similar problem like so: https://github.com/newrelic/newrelic-node-versions/blob/8e4873e3eafe6071a3aa3873acd12a96932390c8/ai-monitoring-tmpl.go#L146-L181

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

1 participant