Skip to content

Method invocation on nil value #1629

Description

@jsumners-nr

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/cobra@v1.7.0/command.go:944 +0x63c
github.com/spf13/cobra.(*Command).ExecuteC(0x10172b500)
	/Users/jsumners/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/jsumners/go/pkg/mod/github.com/spf13/cobra@v1.7.0/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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions