quickfix
quickfix copied to clipboard
ParseMessage panic: assignment to entry in nil map quickfix v0.6.0
I have some simple code to read a FIX message and I keep getting a ParseMessage Panic. I placed the byte array in comments so there aren't any rendering issues
package main
import (
"bytes"
"fmt"
"github.com/quickfixgo/quickfix"
)
func main() {
rawMsg := bytes.NewBufferString("8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039")
fmt.Println(rawMsg.Bytes())
//[56 61 70 73 88 46 52 46 50 1 57 61 49 48 52 1 51 53 61 68 1 51 52 61 50 1 52 57 61 84 87 1 53 50 61 50 48 49 52 48 53 49 53 45 49 57 58 52 57 58 53 54 46 54 53 57 1 53 54 61 73 83 76 68 1 49 49 61 49 48 48 1 50 49 61 49 1 52 48 61 49 1 53 52 61 49 1 53 53 61 84 83 76 65 1 54 48 61 48 48 48 49 48 49 48 49 45 48 48 58 48 48 58 48 48 46 48 48 48 1 49 48 61 48 51 57 1]
var msg quickfix.Message
err := quickfix.ParseMessage(&msg, rawMsg)
if err != nil {
fmt.Println(err)
}
fmt.Println("--", msg)
}
The error message is panic: assignment to entry in nil map
panic: assignment to entry in nil map
goroutine 1 [running]:
github.com/quickfixgo/quickfix.(*FieldMap).add(...)
/Users/ranj/go/pkg/mod/github.com/quickfixgo/[email protected]/field_map.go:208
github.com/quickfixgo/quickfix.ParseMessageWithDataDictionary(0xc000042de8, 0xc0000b0630, 0x0, 0x0, 0x1, 0x171)
/Users/ranj/go/pkg/mod/github.com/quickfixgo/[email protected]/message.go:158 +0x201
github.com/quickfixgo/quickfix.ParseMessage(...)
/Users/ranj/go/pkg/mod/github.com/quickfixgo/[email protected]/message.go:120
main.main()
/Users/ranj/go-fixtest/main.go:16 +0x185
exit status 2
My go.mod looks like this
go 1.12
require (
github.com/mattn/go-sqlite3 v1.13.0 // indirect
github.com/quickfixgo/quickfix v0.6.0
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5 // indirect
github.com/stretchr/testify v1.4.0
)
Looks like this is already fixed in a newer version by the lines below:
https://github.com/quickfixgo/quickfix/blob/76e000323336ea5dcc20385ea79bded291a258eb/message.go#L160-L162
Indeed, running the same test code against newest quickfix produces the output below:
[56 61 70 73 88 46 52 46 50 57 61 49 48 52 51 53 61 68 51 52 61 50 52 57 61 84 87 53 50 61 50 48 49 52 48 53 49 53 45 49 57 58 52 57 58 53 54 46 54 53 57 53 54 61 73 83 76 68 49 49 61 49 48 48 50 49 61 49 52 48 61 49 53 52 61 49 53 53 61 84 83 76 65 54 48 61 48 48 48 49 48 49 48 49 45 48 48 58 48 48 58 48 48 46 48 48 48 49 48 61 48 51 57]
error parsing message: No Fields detected in 8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039
-- {{{map[] {[] <nil>}}} {{map[] {[] <nil>}}} {{map[] {[] <nil>}}} 0001-01-01 00:00:00 +0000 UTC 0xc000092ab0 [] [] false}
I would suggest upgrading to a newer version.