heetch / heetch/avro

panic when encoding array that can contain null values

Open
#118 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
95
Forks
18
PR merge metrics
No merged PRs in 30d

Description

When trying to encode the data type:
```go
type Data struct {
Data *[]*string `json:"data"`
}
```
which is generated with avrogo from the schema
```json
{
"type": "record",
"name": "Data",
"namespace": "test",
"connect.version": 1,
"connect.name": "test.Data",
"default": null,
"fields": [
{
"name": "data",
"default": null,
"type": [
"null",
{
"type": "array",
"items": ["null", "string"]
}
]
}
]
}
```

results in the error:
```
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/heetch/avro.(*encoderBuilder).typeEncoder(0xc000137cc8, {0x539498?, 0xc00012e190?}, {0x53a0a0, 0x4eb000}, {{0x53a0a0, 0x4eb700}, {0x0, 0x0}, 0x0, ...})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:173 +0x190f
github.com/heetch/avro.(*encoderBuilder).typeEncoder(0xc000137cc8, {0x538e08?, 0xc0001282b8?}, {0x53a0a0, 0x4eb700}, {{0x53a0a0, 0x4eb700}, {0x0, 0x0}, 0x0, ...})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:208 +0xbd6
github.com/heetch/avro.(*encoderBuilder).typeEncoder(0xc000137cc8, {0x539498?, 0xc00012e1e0?}, {0x53a0a0, 0x4e8fc0}, {{0x53a0a0, 0x4e8fc0}, {0x4e63e1, 0x4}, 0x0, ...})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:176 +0x3c6
github.com/heetch/avro.(*encoderBuilder).typeEncoder(0xc000177cc8, {0x5393b8?, 0xc00011ca20?}, {0x53a0a0, 0x4f8640}, {{0x53a0a0, 0x4f8640}, {0x0, 0x0}, 0x0, ...})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:149 +0x15b6
github.com/heetch/avro.typeEncoder(0xc00012c120, {0x53a0a0?, 0x4f8640})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:71 +0x210
github.com/heetch/avro.marshalAppend(0xc000164100?, {0xc00016e000, 0x1, 0x64}, {0x4f8640?, 0x0?, 0x0?})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/encode.go:38 +0xd3
github.com/heetch/avro.(*SingleEncoder).Marshal(0xc000164100, {0x538850, 0xc000120000}, {0x4f8640?, 0x0?})
/home/jgresty/go/pkg/mod/github.com/heetch/avro@v0.4.4/singleencoder.go:64 +0x1ad
main.main()
```

I have a runnable example at: https://github.com/jgresty/avrotest

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.