This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 9a27485a0 Writer code generated warning after copyright message. 
Change throw for invalid type for union to give structName in the exception 
text. (#2034)
9a27485a0 is described below

commit 9a27485a0c1efe9ff6c620a32afb365eb3b49e69
Author: Andrew Peter Marlow <[email protected]>
AuthorDate: Thu Jan 12 08:17:45 2023 +0000

    Writer code generated warning after copyright message. Change throw for 
invalid type for union to give structName in the exception text. (#2034)
    
    (cherry picked from commit 1ec0af204bc1c5f196e889c8af33b6e4aa784fee)
---
 lang/c++/impl/avrogencpp.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lang/c++/impl/avrogencpp.cc b/lang/c++/impl/avrogencpp.cc
index 01c4cdbf3..44de923dc 100644
--- a/lang/c++/impl/avrogencpp.cc
+++ b/lang/c++/impl/avrogencpp.cc
@@ -108,6 +108,7 @@ class CodeGen {
     void generateRecordTraits(const NodePtr &n);
     void generateUnionTraits(const NodePtr &n);
     void emitCopyright();
+    void emitGeneratedWarning();
 
 public:
     CodeGen(std::ostream &os, std::string ns,
@@ -326,7 +327,7 @@ static void generateGetterAndSetter(ostream &os,
     os << type << sn << "get_" << name << "() const {\n"
        << "    if (idx_ != " << idx << ") {\n"
        << "        throw avro::Exception(\"Invalid type for "
-       << "union\");\n"
+       << "union " << structName << "\");\n"
        << "    }\n"
        << "    return " << ANY_NS << "::any_cast<" << type << " >(value_);\n"
        << "}\n\n";
@@ -702,17 +703,22 @@ void CodeGen::emitCopyright() {
            " * See the License for the specific language governing "
            "permissions and\n"
            " * limitations under the License.\n"
-           " */\n\n\n";
+           " */\n\n";
+}
+
+void CodeGen::emitGeneratedWarning() {
+    os_ << "/* This code was generated by avrogencpp " << AVRO_VERSION << ". 
Do not edit.*/\n\n";
 }
 
 string CodeGen::guard() {
     string h = headerFile_;
     makeCanonical(h, true);
-    return h + "_" + lexical_cast<string>(random_()) + "__H_";
+    return h + "_" + lexical_cast<string>(random_()) + "_H";
 }
 
 void CodeGen::generate(const ValidSchema &schema) {
     emitCopyright();
+    emitGeneratedWarning();
 
     string h = guardString_.empty() ? guard() : guardString_;
 

Reply via email to