Re: [protobuf] Core dump on upload .proto file

2016-10-17 Thread Stanislav Eismont

>
> Feng, thank you! I did not know about exceptions in protobuf. So your 
> advice is helped me)
>
But I'm still confused, because e.g. 
google::protobuf::Message::SerializeToOstream() may throw 
google::protobuf::FatalException exception in case when serialized data is 
bad ...

Can you please to enlighten me, or provide a link? Thank you!

-- 
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.


Re: [protobuf] Core dump on upload .proto file

2016-10-13 Thread 'Feng Xiao' via Protocol Buffers
On Thu, Oct 13, 2016 at 2:12 AM, Stanislav Eismont <
stanislav.eism...@gmail.com> wrote:

> 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  0x7f9695476c37 in __GI_raise (sig=sig@entry=6) at
> ../nptl/sysdeps/unix/sysv/linux/raise.c:56
> #1  0x7f969547a028 in __GI_abort () at abort.c:89
> #2  0x7f9695b6b535 in __gnu_cxx::__verbose_terminate_handler() ()
> from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #3  0x7f9695b696d6 in ?? () from /usr/lib/x86_64-linux-gnu/
> libstdc++.so.6
> #4  0x7f9695b68799 in ?? () from /usr/lib/x86_64-linux-gnu/
> libstdc++.so.6
> #5  0x7f9695b6934a in __gxx_personality_v0 () from
> /usr/lib/x86_64-linux-gnu/libstdc++.so.6
> #6  0x7f9695e12aa6 in __libunwind_Unwind_Resume () from
> /usr/lib/x86_64-linux-gnu/libunwind.so.8
> #7  0x00b84193 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?
>
Protobuf code base does not work with exceptions:
https://google.github.io/styleguide/cppguide.html#Exceptions

Since the AddError() method is called by protobuf runtime, you'd better not
throw an exception there because protobuf code is not prepared to handle
exceptions at all.



>
>
> 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.
>

-- 
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.