diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-03-01 14:37:51 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-03-15 11:53:14 +0100 |
commit | dd257663217d6d2c098d5a57d8a3f8c5a830310f (patch) | |
tree | b96aa0b14879ab1ea87a3b140edd37a144f2fe40 /ffi/examples | |
parent | f3da2cfee5469c7db87211c45a535f47456d9425 (diff) |
ffi: Improve error reporting.
- Add a status code representing errors.
- Hand out errors as opaque objects. These objects can then be
queried for the numeric status code, and a string representation.
Diffstat (limited to 'ffi/examples')
-rw-r--r-- | ffi/examples/configure.c | 12 | ||||
-rw-r--r-- | ffi/examples/example.c | 6 | ||||
-rw-r--r-- | ffi/examples/keyserver.c | 12 | ||||
-rw-r--r-- | ffi/examples/reader.c | 10 |
4 files changed, 30 insertions, 10 deletions
diff --git a/ffi/examples/configure.c b/ffi/examples/configure.c index dc84fc6e..731d7a4c 100644 --- a/ffi/examples/configure.c +++ b/ffi/examples/configure.c @@ -1,4 +1,5 @@ #define _GNU_SOURCE +#include <assert.h> #include <error.h> #include <errno.h> #include <stdio.h> @@ -20,8 +21,15 @@ main (int argc, char **argv) ks = sq_keyserver_sks_pool (ctx); if (ks == NULL) - error (0, 0, "Initializing Keyserver failed as expected: %s", - sq_last_strerror (ctx)); + { + sq_error_t err = sq_context_last_error (ctx); + assert (sq_error_status (err) == SQ_STATUS_NETWORK_POLICY_VIOLATION); + char *msg = sq_error_string (err); + error (0, 0, "Initializing KeyServer failed as expected: %s", + msg); + sq_string_free (msg); + sq_error_free (err); + } else error (1, 0, "This should not be allowed"); diff --git a/ffi/examples/example.c b/ffi/examples/example.c index 59b48c35..ed4789ca 100644 --- a/ffi/examples/example.c +++ b/ffi/examples/example.c @@ -39,8 +39,10 @@ main (int argc, char **argv) tpk = sq_tpk_from_bytes (ctx, b, st.st_size); if (tpk == NULL) - error (1, 0, "sq_tpk_from_bytes: %s", sq_last_strerror (ctx)); - + { + sq_error_t err = sq_context_last_error (ctx); + error (1, 0, "sq_tpk_from_bytes: %s", sq_error_string (err)); + } sq_tpk_dump (tpk); sq_tpk_free (tpk); sq_context_free (ctx); diff --git a/ffi/examples/keyserver.c b/ffi/examples/keyserver.c index 0683d799..343ee163 100644 --- a/ffi/examples/keyserver.c +++ b/ffi/examples/keyserver.c @@ -19,14 +19,18 @@ main (int argc, char **argv) ks = sq_keyserver_sks_pool (ctx); if (ks == NULL) - error (1, 0, "Initializing Keyserver failed: %s", - sq_last_strerror (ctx)); + { + sq_error_t err = sq_context_last_error (ctx); + error (1, 0, "Initializing Keyserver failed: %s", sq_error_string (err)); + } id = sq_keyid_from_bytes ((uint8_t *) "\x24\x7F\x6D\xAB\xC8\x49\x14\xFE"); tpk = sq_keyserver_get (ctx, ks, id); if (tpk == NULL) - error (1, 0, "Failed to retrieve key: %s", - sq_last_strerror (ctx)); + { + sq_error_t err = sq_context_last_error (ctx); + error (1, 0, "Failed to retrieve key: %s", sq_error_string (err)); + } sq_tpk_dump (tpk); sq_tpk_free (tpk); diff --git a/ffi/examples/reader.c b/ffi/examples/reader.c index dde98016..439d6510 100644 --- a/ffi/examples/reader.c +++ b/ffi/examples/reader.c @@ -40,11 +40,17 @@ main (int argc, char **argv) reader = sq_reader_from_bytes (b, st.st_size); if (reader == NULL) - error (1, 0, "sq_reader_from_bytes: %s", sq_last_strerror (ctx)); + { + sq_error_t err = sq_context_last_error (ctx); + error (1, 0, "sq_reader_from_bytes: %s", sq_error_string (err)); + } tpk = sq_tpk_from_reader (ctx, reader); if (tpk == NULL) - error (1, 0, "sq_tpk_from_reader: %s", sq_last_strerror (ctx)); + { + sq_error_t err = sq_context_last_error (ctx); + error (1, 0, "sq_tpk_from_reader: %s", sq_error_string (err)); + } sq_tpk_dump (tpk); sq_tpk_free (tpk); |