[
https://issues.apache.org/jira/browse/AVRO-3693?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated AVRO-3693:
---------------------------------
Labels: pull-request-available (was: )
> avrogencpp Invalid type for union exception does not identify which union
> -------------------------------------------------------------------------
>
> Key: AVRO-3693
> URL: https://issues.apache.org/jira/browse/AVRO-3693
> Project: Apache Avro
> Issue Type: Improvement
> Components: c++
> Affects Versions: 1.11.0
> Reporter: Andrew Peter Marlow
> Priority: Minor
> Labels: pull-request-available
> Original Estimate: 24h
> Time Spent: 10m
> Remaining Estimate: 23h 50m
>
> This is a small enhancement request for the avrogencpp code generator, to
> help identify a deserialisation issue better. When a structure sent by avro
> contains unions and a union part of a message is de-serialized without
> checking first that it is present, invalid type for union is thrown. However
> it does not identify which union. It could include the structName in the
> exception, then it would be possible to tie down the exception to the precise
> union that got the error.
> If the file below, Empdetails.avsc is given to avrogencpp, it will show a
> get_int function for a union where the exception text does not identify the
> union.
> {code:java}
> {
> "type" : "record",
> "namespace" : "tutorialspoint",
> "name" : "Empdetails",
> "fields" :
> [
> { "name" : "experience", "type": ["int", "null"] }, { "name" : "age",
> "type": "int" }
> ]
> } {code}
> In this particular case there is only one union so there is no problem but
> when there are multiple unions they all get the same exception text so it is
> hard to tell from where the throw came.
> I have the change waiting in the wings for a PR. The change includes the
> structName in the exception. With this change the avrogencpp generate code
> looks as follows:
> {code:java}
> inline
> int32_t Empdetails_avsc_Union__0__::get_int() const {
> if (idx_ != 0) {
> throw avro::Exception("Invalid type for union
> Empdetails_avsc_Union__0__");
> }
> return std::any_cast<int32_t >(value_);
> } {code}
> With this done for every union in a structure it will be clear which throw
> has executed when the exception is reported.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)