aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 20:14:24 +0200
committerDavid Robillard <d@drobilla.net>2019-12-19 20:52:31 -0500
commite9e850f798885c528ef9413fd8d12dd0ef9e06c1 (patch)
treeca53b045b92f58981c6e7352c883e8b1d4b93c5c /src
parent5e2a5940e17f498f4cbec37ee7380a42f511c82a (diff)
downloadserd-e9e850f798885c528ef9413fd8d12dd0ef9e06c1.tar.gz
serd-e9e850f798885c528ef9413fd8d12dd0ef9e06c1.tar.bz2
serd-e9e850f798885c528ef9413fd8d12dd0ef9e06c1.zip
Move error handling to world
Diffstat (limited to 'src')
-rw-r--r--src/reader.c2
-rw-r--r--src/serd_internal.h11
-rw-r--r--src/world.c25
-rw-r--r--src/world.h5
-rw-r--r--src/writer.c27
5 files changed, 37 insertions, 33 deletions
diff --git a/src/reader.c b/src/reader.c
index 138ef336..3a72a3e4 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -36,7 +36,7 @@ r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...)
va_start(args, fmt);
const Cursor* const cur = &reader->source.cur;
const SerdError e = { st, cur->filename, cur->line, cur->col, fmt, &args };
- serd_error(reader->world, &e);
+ serd_world_error(reader->world, &e);
va_end(args);
return 0;
}
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 172343b8..601af56c 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -69,15 +69,4 @@ serd_bufalloc(size_t size)
#endif
}
-static inline void
-serd_error(const SerdWorld* world, const SerdError* e)
-{
- if (world->error_sink) {
- world->error_sink(world->error_handle, e);
- } else {
- fprintf(stderr, "error: %s:%u:%u: ", e->filename, e->line, e->col);
- vfprintf(stderr, e->fmt, *e->args);
- }
-}
-
#endif // SERD_INTERNAL_H
diff --git a/src/world.c b/src/world.c
index 07439137..0210760d 100644
--- a/src/world.c
+++ b/src/world.c
@@ -16,8 +16,33 @@
#include "serd_internal.h"
+#include <stdarg.h>
+
#include "world.h"
+SerdStatus
+serd_world_error(const SerdWorld* world, const SerdError* e)
+{
+ if (world->error_sink) {
+ world->error_sink(world->error_handle, e);
+ } else {
+ fprintf(stderr, "error: %s:%u:%u: ", e->filename, e->line, e->col);
+ vfprintf(stderr, e->fmt, *e->args);
+ }
+ return e->status;
+}
+
+SerdStatus
+serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ const SerdError e = { st, NULL, 0, 0, fmt, &args };
+ serd_world_error(world, &e);
+ va_end(args);
+ return st;
+}
+
SerdWorld*
serd_world_new(void)
{
diff --git a/src/world.h b/src/world.h
index 88241b0e..7e451b0e 100644
--- a/src/world.h
+++ b/src/world.h
@@ -24,4 +24,9 @@ struct SerdWorldImpl {
void* error_handle;
};
+SerdStatus serd_world_error(const SerdWorld* world, const SerdError* e);
+
+SerdStatus
+serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...);
+
#endif // SERD_WORLD_H
diff --git a/src/writer.c b/src/writer.c
index 4c9f625d..4223581a 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -133,22 +133,6 @@ supports_abbrev(const SerdWriter* writer)
return writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG;
}
-static void
-w_err(SerdWriter* writer, SerdStatus st, const char* fmt, ...)
-{
- /* TODO: This results in errors with no file information, which is not
- helpful when re-serializing a file (particularly for "undefined
- namespace prefix" errors. The statement sink API needs to be changed to
- add a Cursor parameter so the source can notify the writer of the
- statement origin for better error reporting. */
-
- va_list args;
- va_start(args, fmt);
- const SerdError e = { st, NULL, 0, 0, fmt, &args };
- serd_error(writer->world, &e);
- va_end(args);
-}
-
static inline WriteContext*
anon_stack_top(SerdWriter* writer)
{
@@ -187,7 +171,8 @@ write_character(SerdWriter* writer, const uint8_t* utf8, size_t* size)
const uint32_t c = parse_utf8_char(utf8, size);
switch (*size) {
case 0:
- w_err(writer, SERD_ERR_BAD_ARG, "invalid UTF-8: %X\n", utf8[0]);
+ serd_world_errorf(
+ writer->world, SERD_ERR_BAD_ARG, "invalid UTF-8: %X\n", utf8[0]);
return sink(replacement_char, sizeof(replacement_char), writer);
case 1:
snprintf(escape, sizeof(escape), "\\u%04X", utf8[0]);
@@ -576,7 +561,8 @@ write_curie(SerdWriter* const writer,
case SERD_NTRIPLES:
case SERD_NQUADS:
if ((st = serd_env_expand(writer->env, node, &prefix, &suffix))) {
- w_err(writer, st, "undefined namespace prefix `%s'\n", node_str);
+ serd_world_errorf(writer->world, st,
+ "undefined namespace prefix `%s'\n", node_str);
return false;
}
write_sep(writer, SEP_URI_BEGIN);
@@ -837,9 +823,8 @@ serd_writer_end_anon(SerdWriter* writer,
return SERD_SUCCESS;
}
if (serd_stack_is_empty(&writer->anon_stack) || writer->indent == 0) {
- w_err(writer, SERD_ERR_UNKNOWN,
- "unexpected end of anonymous node\n");
- return SERD_ERR_UNKNOWN;
+ return serd_world_errorf(writer->world, SERD_ERR_UNKNOWN,
+ "unexpected end of anonymous node\n");
}
--writer->indent;
write_sep(writer, SEP_ANON_END);