diff options
author | David Robillard <d@drobilla.net> | 2018-05-10 20:14:24 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | a4f6754a4048f2bcb04482938d5a98e9ab77d4fc (patch) | |
tree | 5a9ee51f51ae4a1c7116d94cc833f10a5532ff87 /src/writer.c | |
parent | 10c706a040abeaf5c82db54086d4edb03a995cf3 (diff) | |
download | serd-a4f6754a4048f2bcb04482938d5a98e9ab77d4fc.tar.gz serd-a4f6754a4048f2bcb04482938d5a98e9ab77d4fc.tar.bz2 serd-a4f6754a4048f2bcb04482938d5a98e9ab77d4fc.zip |
Move error handling to world
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/src/writer.c b/src/writer.c index de0e80a7..d632c7af 100644 --- a/src/writer.c +++ b/src/writer.c @@ -22,11 +22,11 @@ #include "stack.h" #include "string_utils.h" #include "uri_utils.h" +#include "world.h" #include "serd/serd.h" #include <assert.h> -#include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -139,24 +139,7 @@ supports_uriref(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 SERD_PURE_FUNC -WriteContext* +static inline WriteContext* anon_stack_top(SerdWriter* writer) { assert(!serd_stack_is_empty(&writer->anon_stack)); @@ -194,7 +177,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]); @@ -615,10 +599,10 @@ write_uri_node(SerdWriter* const writer, if (!has_scheme && !supports_uriref(writer) && !serd_env_base_uri(writer->env)) { - w_err(writer, - SERD_ERR_BAD_ARG, - "syntax does not support URI reference <%s>\n", - node_str); + serd_world_errorf(writer->world, + SERD_ERR_BAD_ARG, + "syntax does not support URI reference <%s>\n", + node_str); return false; } @@ -664,7 +648,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); @@ -933,20 +918,24 @@ serd_writer_end_anon(SerdWriter* writer, const SerdNode* node) if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) { 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); free_context(writer); writer->context = *anon_stack_top(writer); serd_stack_pop(&writer->anon_stack, sizeof(WriteContext)); + const bool is_subject = serd_node_equals(node, writer->context.subject); if (is_subject) { serd_node_set(&writer->context.subject, node); memset(writer->context.predicate, 0, sizeof(SerdNode)); } + return SERD_SUCCESS; } |