enbility / eebus-go

EEBUS protocol implementation in go
https://enbility.net
MIT License
52 stars 14 forks source link

Check panics #41

Closed DerAndereAndi closed 1 year ago

DerAndereAndi commented 1 year ago

These similar panics sometimes occur all the time, sometimes never:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0xb89ac4]

goroutine 1 [running]:
github.com/enbility/eebus-go/features.(*DeviceDiagnosis).GetState(0x3896458)
    /Users/andreaslinde/go/pkg/mod/github.com/enbility/eebus-go@v0.1.3/features/devicediagnosis.go:57 +0x90
github.com/enbility/cemd/emobility.(*EMobilityImpl).EVCurrentChargeState(0x3160080)
    /Users/andreaslinde/go/pkg/mod/github.com/enbility/cemd@v0.1.3/emobility/public.go:21 +0x34

or

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0xb8d8cc]

goroutine 178 [running]:
github.com/enbility/eebus-go/features.(*Measurement).GetValuesPerPhaseForScope(0x574a300, {0x19b7bec, 0x9}, 0x574a2f8)
    /Users/andreaslinde/go/pkg/mod/github.com/enbility/eebus-go@v0.1.3/features/measurement.go:137 +0xbc
github.com/enbility/cemd/emobility.(*EMobilityImpl).EVCurrentsPerPhase(0x4844ec0)
    /Users/andreaslinde/go/pkg/mod/github.com/enbility/cemd@v0.1.3/emobility/public.go:133 +0x4c
DerAndereAndi commented 1 year ago

Fixed with https://github.com/enbility/eebus-go/commit/33eb0b563e39a5adb97f22199bc731d1d96ac498 and added test

Explanation available here: https://stackoverflow.com/questions/62441652/how-do-nil-interface-values-work-in-golang

Thanks for the hint @andig