Hi all!

I use protobuf in my c++ app on Ubuntu 14.04 system. libprotobuf-dev, 
libprotoc-dev packages has static linkage with app. Important to note that 
this packages builded WITHOUT -DNDEBUG compiler flag (i.e. debug/test mode, 
where GOOGLE_DCHECK macro on).

I have the next objects to working with protobuf:

    class ExceptionMfec : public MultiFileErrorCollector
    {
        public
            void AddError (const string &filename,
                           int line, int column,
                           const string &message)
            {
                const std::string errMesage =
                             //construct msg here

                throw std::runtime_error (errMesage);
            }
    };

    DiskSourceTree dst_;
    ExceptionMfec mfec_;
    Importer importer_ (&dst_, &mfec_);


    Now if I run my app using .proto file with syntax error:
    
    message Msg {
        required int32 foo = 1;
    }
    some_garabage_here

   I got correct error message like: "... Expected top-level statement 
(e.g. "message")." But if .proto file has logic error like:

    message Msg {
         required nonexistent_type foo = 1;
    }

Then I got core dump with following output:

terminate called after throwing an instance of 'std::runtime_error'
  what():  CHECK failed: checkpoints_.empty(): 
Aborted (core dumped)

The core dump is:

#0  0x00007f9695476c37 in __GI_raise (sig=sig@entry=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f969547a028 in __GI_abort () at abort.c:89
#2  0x00007f9695b6b535 in __gnu_cxx::__verbose_terminate_handler() () from 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007f9695b696d6 in ?? () from 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007f9695b68799 in ?? () from 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007f9695b6934a in __gxx_personality_v0 () from 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007f9695e12aa6 in __libunwind_Unwind_Resume () from 
/usr/lib/x86_64-linux-gnu/libunwind.so.8
#7  0x0000000000b84193 in google::protobuf::compiler::Importer::~Importer() 
()


Looks like protobuf invoke my AddError() function, then first exception was 
thrown. Then another exception was generated inside ~Importer() which 
declared as noexcept(true) and program terminated.

If what I have written above is true, then protobuf behavior is very 
strange: exception from destructor is bad, exception from noexcept 
destructor even worse.
Is there a workaround of this issue, in order to get correct error message?

***************************************************************************************************************************************************************************************

I also see another approach to avoid issue with core. I may build protobuf 
package WITH -DNDEBUG, then GOOGLE_DCHECK macro off, and I'll get correct 
error message without core.
But I need protobuf runtime checks like ckeck that 'required' fields is 
present in serialized data, and other.

Can I check that required fields are present using some protobuf API?


Thanks in advance!


-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to