You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "Martin Tzvetanov Grigorov (Jira)" <ji...@apache.org> on 2023/01/12 08:28:00 UTC

[jira] [Resolved] (AVRO-3693) avrogencpp Invalid type for union exception does not identify which union

     [ https://issues.apache.org/jira/browse/AVRO-3693?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Martin Tzvetanov Grigorov resolved AVRO-3693.
---------------------------------------------
    Fix Version/s: 1.12.0
                   1.11.2
         Assignee: Andrew Peter Marlow
       Resolution: Fixed

> 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
>            Assignee: Andrew Peter Marlow
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 1.12.0, 1.11.2
>
>   Original Estimate: 24h
>          Time Spent: 0.5h
>  Remaining Estimate: 23.5h
>
> 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)