uhppoted / uhppote-cli

Go CLI for the UHPPOTE UT0311 TCP/IP access controller boards
MIT License
8 stars 4 forks source link

uhppote-cli get-events throws a panic #1

Closed uhppoted closed 4 years ago

uhppoted commented 4 years ago

Moved from https://github.com/twystd/uhppote-go/issues/4

grenade@quadbrat ~/Downloads/uhppoted_v0.6.1-linux/uhppoted_v0.6.1 $ ./uhppote-cli get-events 423140069 --debug
panic: Cannot unmarshal field with type 'types.DateTime'

goroutine 1 [running]:
github.com/uhppoted/uhppote-core/encoding/UTO311-L0x.unmarshal(0xc00014c000, 0x40, 0x800, 0x6474e0, 0xc000010840, 0x199, 0x800, 0x40)
    ~/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.1/encoding/UTO311-L0x/UT0311-L0x.go:296 +0x13c9
github.com/uhppoted/uhppote-core/encoding/UTO311-L0x.Unmarshal(0xc00014c000, 0x40, 0x800, 0x5f8400, 0xc000010840, 0xc00006f0b0, 0x0)
    ~/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.1/encoding/UTO311-L0x/UT0311-L0x.go:165 +0x180
github.com/uhppoted/uhppote-core/uhppote.(*UHPPOTE).receive(0xc00006e7e0, 0xc00000e078, 0x5f8400, 0xc000010840, 0xc000016a60, 0x0)
    ~/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.1/uhppote

/uhppote.go:246 +0x32a
github.com/uhppoted/uhppote-core/uhppote.(*UHPPOTE).Execute(0xc00006e7e0, 0xc019389ae5, 0x62fce0, 0xc000016a60, 0x5f8400, 0xc000010840, 0x0, 0x0)
    ~/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.1/uhppote/uhppote.go:108 +0x1cf
github.com/uhppoted/uhppote-core/uhppote.(*UHPPOTE).GetEvent(0xc00006e7e0, 0x19389ae5, 0x15, 0x65d933, 0x19)
    ~/go/pkg/mod/github.com/uhppoted/uhppote-core@v0.6.1/uhppote/get_event.go:16 +0x96
github.com/uhppoted/uhppote-cli/commands.(*GetEvents).Execute(0x84e3e0, 0xc00006e7e0, 0xc00010a780, 0x0, 0x0)
    ~/Development/uhppote/uhppoted/uhppote-cli/commands/get_events.go:19 +0x9e
main.main()
    ~/Development/uhppote/uhppoted/uhppote-cli/cmd/uhppote-cli/main.go:121 +0x756
uhppoted commented 4 years ago

Hi Rob,

Ref. https://github.com/twystd/uhppote-go/issues/4.

Can you please run the command:

./uhppote-cli --debug get-events 423140069 

and let me have the output? I haven't been able to reproduce the problem on my system so it seems like your system is returning an unexpected response.

(BTW, uhppote-cli expects the global options like --debug and --config before the command)

twystd commented 4 years ago

Reproduced:

./uhppote-cli --debug get-events 423195744

... request
 ...          00000000  17 b0 00 00 60 74 39 19  00 00 00 00 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
 ... sent 64 bytes to 192.168.1.255:60000
 ... received 64 bytes from 192.168.1.104:60000
 ... response
 ...          00000000  17 b0 00 00 60 74 39 19  00 00 00 00 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
panic: Cannot unmarshal field with type 'types.DateTime'

goroutine 1 [running]:
uhppote/encoding/UTO311-L0x.unmarshal(0x24c0000, 0x40, 0x800, 0x1d2e50, 0x2462360, 0x199, 0x1c1, 0x380)
    .../uhppote/uhppote-go/src/uhppote/encoding/UTO311-L0x/UT0311-L0x.go:296 +0x105c
uhppote/encoding/UTO311-L0x.Unmarshal(0x24c0000, 0x40, 0x800, 0x1a58e8, 0x2462360, 0x3, 0x3)
    .../uhppote/uhppote-go/src/uhppote/encoding/UTO311-L0x/UT0311-L0x.go:165 +0x140
uhppote.(*UHPPOTE).receive(0x240a8a0, 0x240e3c8, 0x1a58e8, 0x2462360, 0x2412444, 0x0)
    .../uhppote/uhppote-go/src/uhppote/uhppote.go:246 +0x260
uhppote.(*UHPPOTE).Execute(0x240a8a0, 0x19397460, 0x1c5350, 0x2412444, 0x1a58e8, 0x2462360, 0x0, 0x0)
    .../uhppote/uhppote-go/src/uhppote/uhppote.go:108 +0x154
uhppote.(*UHPPOTE).GetEvent(0x240a8a0, 0x19397460, 0x0, 0x1e3b9f, 0x19, 0x19397460)
    .../uhppote/uhppote-go/src/uhppote/get_event.go:16 +0x74
uhppote-cli/commands.(*GetEventsCommand).Execute(0x344180, 0x240a8a0, 0x240ac80, 0x0, 0x0)
    .../uhppote/uhppote-go/src/uhppote-cli/commands/get_events.go:17 +0x6c
main.main()
    .../uhppote/uhppote-go/src/cmd/uhppote-cli/main.go:111 +0x5bc
uhppoted commented 4 years ago

Root cause

A controller with no stored events returns a response with an event index of 0 and no other valid fields.

Affected modules

Status

Provisional fix pushed to master branch across all modules.

uhppoted commented 4 years ago

Tested with uhppote-cli:

./uhppote-cli --debug get-events 423195744
 ... request
 ...          00000000  17 b0 00 00 60 74 39 19  00 00 00 00 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
 ... sent 64 bytes to 192.168.1.255:60000
 ... received 64 bytes from 192.168.1.104:60000
 ... response
 ...          00000000  17 b0 00 00 60 74 39 19  00 00 00 00 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
 ... request
 ...          00000000  17 b0 00 00 60 74 39 19  ff ff ff ff 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
 ... sent 64 bytes to 192.168.1.255:60000
 ... received 64 bytes from 192.168.1.104:60000
 ... response
 ...          00000000  17 b0 00 00 60 74 39 19  00 00 00 00 00 00 00 00  |....`t9.........|
 ...          00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
 ...          
423195744  NO EVENTS
uhppoted commented 4 years ago

Tested with uhppoted-rest:

curl -X GET "http://127.0.0.1:8080/uhppote/device/303986753/events" -H "accept: application/json"
{
  "events": {}
}
uhppoted commented 4 years ago

Tested with uhppoted-mqtt:

{"message": {"request": {
          "client-id": "QWERTY54",
          "device-id": 303986753,
          "reply-to": "twystd/uhppoted/reply/97531",
          "request-id": "AH173635G3"
}}}
{
          "hmac": "ea92d14866802b8804ffa5b8710a6a27d0781fc53321790a7409810f0848419d",
          "message": {
                    "reply": {
                              "client-id": "QWERTY54",
                              "device-id": 303986753,
                              "events": {},
                              "method": "get-events",
                              "nonce": 68,
                              "request-id": "AH173635G3",
                              "server-id": "twystd-uhppoted"
                    },
                    "signature": "lNEo/xc28coJlZk9WfxOYXzrwTnekQwBg4mANcNFx+RaaogTEjqHAIWT8J0LqVYUT1LxgnOzv4KbUMdqo2PXnk2QZbC+YuzQvkE99xWHvy1kqGwJhl4XoaYD88pT34GfPslCgykWiwauytzxszY5lkYbgegwCipXOhuqW+Y1sf3NXnJV3jrE4uFw9u4cTJ7aV27+QSrXvRPJvY6S/Vqln9dIPwM5/gdrPggSbfRZAxbvfLrm0i6kfmVJ3qIp651z+eIIGpA4oFMZ64RiUQoPQy/dMZzoUXA+Io8NBPFy+4u7aaxrbwe5f6rRrJJPG6jR01F0UaIu73+A7LDNDXOavw=="
          }
}
uhppoted commented 4 years ago

Provisionally fixed in master branches, pending release v0.6.2.

uhppoted commented 4 years ago

Fixed in release v0.6.2