aakash-sahai / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

Add error return codes #7

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently nanopb returns just `false` when any error of any kind occurs. Even 
though many applications likely treat all errors in the same way (i.e. it 
doesn't matter if it is an IO error or an invalid message), some applications 
would benefit from more detailed errors. More importantly, it would make 
debugging a lot easier to have atleast a rough idea of what causes an error.

Error codes would not increase code size by much, but they will break the 
current interface. Whereas `if (!pb_encode(..)) { error }` works now, it would 
be the exact opposite when following the convention that PB_OK = 0 and 
PB_READ_ERROR = 1 etc.

Therefore this bug is postponed until some major release.

Original issue reported on code.google.com by Petteri.Aimonen on 1 Mar 2012 at 10:47

GoogleCodeExporter commented 9 years ago
There is a backwards compatible way to add the error codes:

#ifdef PB_USE_ERROR_CODES
/* New api that uses error codes */
#define PB_OK 0
#define PB_IO_ERROR 1 /* Error in stream input/output */
#define PB_FMT_ERROR 2 /* Message binary format is invalid */
#define PB_SIZE_ERROR 3 /* Field exceeds max_size or max_count */
#else
/* Old api that uses true/false */
#define PB_OK true
#define PB_IO_ERROR false
#define PB_FMT_ERROR false
#define PB_SIZE_ERROR false
#endif

This way code written like   if (pb_encode(...) == PB_OK)  will work with 
either configuration, and code written like  if (pb_encode(...))  will work in 
the legacy config.

Original comment by Petteri.Aimonen on 31 Jul 2012 at 4:24

GoogleCodeExporter commented 9 years ago
Another way would be to add the error code to the pb_istream/pb_ostream 
structure. Would not require any changes to the current applications.

Original comment by Petteri.Aimonen on 31 Jul 2012 at 4:33

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 0fb5e5e06832.

Original comment by Petteri.Aimonen on 24 Aug 2012 at 6:23

GoogleCodeExporter commented 9 years ago
Please consider to apply this (trivial) patch.

Original comment by jens.ste...@gmail.com on 26 Nov 2012 at 11:47

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, applied:
https://code.google.com/p/nanopb/source/detail?r=068de05c51b7b46e33ef87b8d78c9dd
a6704abc8

Original comment by Petteri.Aimonen on 27 Nov 2012 at 5:56

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 035264711897.

Original comment by Petteri.Aimonen on 9 Mar 2013 at 12:49

GoogleCodeExporter commented 9 years ago
Fix released in 0.2.1

Original comment by Petteri.Aimonen on 14 Apr 2013 at 7:19