vapor-ware / synse-sdk

SDK for Synse Plugins in Go
https://synse.readthedocs.io/en/latest/sdk/intro/
GNU General Public License v3.0
3 stars 4 forks source link

Crash loading device config #480

Closed MatthewHink closed 3 years ago

MatthewHink commented 3 years ago

Hit this with the busway today. It's a crash with little indication as to why in a 20K line yaml file.

--- FAIL: TestLargeDeviceConfig (13.96s)
panic: reflect: call of reflect.flag.mustBeExported on zero Value [recovered]
    panic: reflect: call of reflect.flag.mustBeExported on zero Value

goroutine 18 [running]:
testing.tRunner.func1.1(0xde4980, 0xc000bc4aa0)
    /usr/local/go/src/testing/testing.go:940 +0x421
testing.tRunner.func1(0xc0001c7440)
    /usr/local/go/src/testing/testing.go:943 +0x600
panic(0xde4980, 0xc000bc4aa0)
    /usr/local/go/src/runtime/panic.go:975 +0x3e3
reflect.flag.mustBeExportedSlow(0x0)
    /usr/local/go/src/reflect/value.go:222 +0xe9
reflect.flag.mustBeExported(...)
    /usr/local/go/src/reflect/value.go:216
reflect.Value.Set(0xddcbc0, 0xc000bcf8b0, 0x194, 0x0, 0x0, 0x0)
    /usr/local/go/src/reflect/value.go:1527 +0x65
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xddcbc0, 0xc000bcf8b0, 0x194, 0xddcbc0, 0xc000bcf8a0, 0x94)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:73 +0xcb0
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xdeb2e0, 0xc00070a0e8, 0x195, 0xdeb2e0, 0xc000021290, 0x15)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:127 +0x893
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xddcbc0, 0xc000bcf6e0, 0x194, 0xddcbc0, 0xc000bcf6d0, 0x94)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:76 +0xc31
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xdeb2e0, 0xc00070a0c8, 0x195, 0xdeb2e0, 0xc000020f30, 0x15)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:127 +0x893
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xddcbc0, 0xc00083d510, 0x194, 0xddcbc0, 0xc00083c010, 0x194)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:76 +0xc31
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xdac180, 0xc000bc4820, 0x197, 0xdac180, 0xc000bc4800, 0x97)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:84 +0xead
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xddcbc0, 0xc000bce930, 0x194, 0xddcbc0, 0xc000bce920, 0x94)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:76 +0xc31
github.com/vapor-ware/synse-sdk/sdk/utils.redactRecursive(0xded380, 0xc00070a000, 0x195, 0xded380, 0xc0001c33e0, 0x15)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:127 +0x893
github.com/vapor-ware/synse-sdk/sdk/utils.RedactPasswords(0xded380, 0xc0001c33e0, 0xeb6ec3, 0x4)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/utils/redact.go:46 +0x10e
github.com/vapor-ware/synse-sdk/sdk/config.(*Loader).read(0xc00009f8c0, 0xeba99e, 0x8, 0x0, 0x0)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/config/config.go:426 +0x77b
github.com/vapor-ware/synse-sdk/sdk/config.(*Loader).Load(0xc00009f8c0, 0xeba99e, 0x8, 0x1, 0xc000044eb0)
    /home/mhink/go/pkg/mod/github.com/vapor-ware/synse-sdk@v0.1.0-alpha.0.20200724155421-64f57718083f/sdk/config/config.go:159 +0x588
github.com/vapor-ware/synse-modbus-ip-plugin/pkg/config.TestLargeDeviceConfig(0xc0001c7440)
    /home/mhink/go/src/github.com/vapor-ware/synse-modbus-ip-plugin/pkg/config/deviceconfig_test.go:60 +0x212
testing.tRunner(0xc0001c7440, 0xee6010)
    /usr/local/go/src/testing/testing.go:991 +0x1ec
created by testing.(*T).Run
MatthewHink commented 3 years ago

Happens on an untyped nil interface value such as below. The trick is going to be getting the key name in the error message. Line number may be best, but that is likely even more difficult. Probably simplest is to emit map key names as we traverse under debug logging (?)

  - type: macAddressWide
    handler: read_only_holding_register
    data:
      host: "10.193.12.210"
      port: 502
      timeout: 10s
      failOnError: false
      type: macaddresswide
      # This is the problem here. This is an untyped nil interface value.
      width:
    context:
      rack: r1
      model: AC CPM
    tags:
      - 'vapor/rack:r1'
    instances:
      - info: LAN Mac Address
        output: macAddressWide
        data:
          address: 5
MatthewHink commented 3 years ago

Other ways:

Both are less prettier code-wise, but may be more effective as far as quickly pointing out the config error. The thing is that the error happens one stack frame down from good information to put in the error message. (recursion)