Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema.Codec() will return nil, without print any warning #66

Closed
dbakit opened this issue Dec 24, 2021 · 2 comments
Closed

schema.Codec() will return nil, without print any warning #66

dbakit opened this issue Dec 24, 2021 · 2 comments

Comments

@dbakit
Copy link

dbakit commented Dec 24, 2021

	schemaRegistryClient := srclient.CreateSchemaRegistryClient(schemaRegistryUrl)
	for {
		msg, err := c.ReadMessage(-1)
		if err != nil {
			logger.Error("Read Message Failed", zap.Error(err))
			continue
		}
		logger.Info("Get a message", zap.Any("Value", msg.Value), zap.Any("Header", msg.Headers))
		schemaID := binary.BigEndian.Uint32(msg.Value[1:5])
		schema, err := schemaRegistryClient.GetSchema(int(schemaID))
		if err != nil {
			logger.Fatal("Get Schema Failed", zap.Uint32("SchemaID", schemaID), zap.Error(err))
		}
		logger.Info("Schema info", zap.Any("Schema", schema.Schema()))
		content := msg.Value[5:]
		logger.Info("Content", zap.Any("RawData", content))
		native, _, err := schema.Codec().NativeFromBinary(content)
		if err != nil {
			logger.Fatal("Decode message failed!", zap.Error(err))
		}
		fmt.Printf("Here is the message %v\n", native)
	

Hi, When I use this example code from readme, I got the right schema, but when decode the content, the function schema.Codec().NativeFromBinary(content) paniced with this error: panic: runtime error: invalid memory address or nil pointer dereference. Could someone tell me, how could I fix it?

Total Logs are:

2021-12-24T14:08:24.694+0800	INFO	Get a message	{"Value": "AAAAAUQAAiAxMTM4ODE2NzcwMTM5NDUxAhQxMjM0NTc0NTMxFiowMzE2MDA5MTM4AhAxNjAwOTE1MwICMNSfAigyMDIwLTA1LTI4VDIwOjE2OjQ4WgAYYXdiOHh2cDJza3NnBjE0MgIzDDAwMDAwMQJBAgAMMDAwMDAwAgIAAgQnEAIEJqwCBCcQAjACAAACMgIIMDAwMAIM5oiQ5YqfAgACAAIAAgACAgACAgACAmQoOTg1MTI4MzUzNzA2NTA4OTcwMTIIMDAwOAICMAIwAjEEMDMCAAIx1J8CAgACAAIAAgACAAIEJxACAgACAjACAAIAAhg2OTIxNTY0NTg2OTQAAgAAAjACBGFhAgACAAACAAA2eyJleHRTeXN0ZW1JZCI6ICJBSVBfQVVUTyJ9AAIwAtSfAgIAFjEuNS4wLkZpbmFsCm15c3FsGnFtX3Rlc3RfbXlzcWyoiuGmvV8ACHRydWUceWluZzk5X2Z1bmR0eG4AAhRmdW5kX29yZGVyAAAgbXlzcWwtYmluLjAwMDAwMYbgpO8DAAAAAnICxorhpr1fAA==", "Header": null}
2021-12-24T14:08:24.850+0800	INFO	Schema info	{"Schema": "{\"type\":\"record\",\"name\": ****** }
2021-12-24T14:08:24.850+0800	INFO	Content	{"RawData": "AAIgMTEzODgxNjc3MDEzOTQ1MQIUMTIzNDU3NDUzMRYqMDMxNjAwOTEzOAIQMTYwMDkxNTMCAjDUnwIoMjAyMC0wNS0yOFQyMDoxNjo0OFoAGGF3Yjh4dnAyc2tzZwYxNDICMwwwMDAwMDECQQIADDAwMDAwMAICAAIEJxACBCasAgQnEAIwAgAAAjICCDAwMDACDOaIkOWKnwIAAgACAAIAAgIAAgIAAgJkKDk4NTEyODM1MzcwNjUwODk3MDEyCDAwMDgCAjACMAIxBDAzAgACMdSfAgIAAgACAAIAAgACBCcQAgIAAgIwAgACAAIYNjkyMTU2NDU4Njk0AAIAAAIwAgRhYQIAAgAAAgAANnsiZXh0U3lzdGVtSWQiOiAiQUlQX0FVVE8ifQACMALUnwICABYxLjUuMC5GaW5hbApteXNxbBpxbV90ZXN0X215c3FsqIrhpr1fAAh0cnVlHHlpbmc5OV9mdW5kdHhuAAIUZnVuZF9vcmRlcgAAIG15c3FsLWJpbi4wMDAwMDGG4KTvAwAAAAJyAsaK4aa9XwA="}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x66f3c3]

goroutine 1 [running]:
github.com/linkedin/goavro/v2.(*Codec).NativeFromBinary(0xc0000a2280, {0xc00009a005, 0x1a0, 0x1a0})
	/Users/***/go/pkg/mod/github.com/linkedin/goavro/v2@v2.10.1/codec.go:344 +0x23
@dbakit
Copy link
Author

dbakit commented Dec 24, 2021

// Codec ensures access to Codec
// Will try to initialize a new one if it hasn't been initialized before
// Will return nil if it can't initialize a codec from the schema
func (schema *Schema) Codec() *goavro.Codec {
	if schema.codec == nil {
		codec, err := goavro.NewCodec(schema.Schema())
		if err == nil {
			schema.codec = codec
		}
	}
	return schema.codec
}

The function Codec() return nill, and not return the err info...

@dbakit
Copy link
Author

dbakit commented Dec 24, 2021

the real reason is linkedin/goavro#202: The goavro, which srcclient used to decode arvo bytes, not support decimal type.

@dbakit dbakit closed this as completed Dec 24, 2021
@dbakit dbakit changed the title schema.Codec().NativeFromBinary(content) got paniced schema.Codec() will return nil, without print any warning Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant