From 76575769f304c80d6d0800b33ec625dd25b6dd49 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 5 Sep 2002 14:21:15 +0000 Subject: [PATCH] working on better error reporting of validity errors, especially providing * error.c valid.c: working on better error reporting of validity errors, especially providing an accurate context. * result/valid/xlink.xml.err result/valid/rss.xml.err: better error reports in those cases. Daniel --- ChangeLog | 7 +++++++ error.c | 31 ++++++++++++++++++++++--------- result/valid/rss.xml.err | 2 +- result/valid/xlink.xml.err | 2 +- valid.c | 31 ++++++++++++++++++++----------- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 824c70bd..5beb6e24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Sep 5 16:19:18 CEST 2002 Daniel Veillard + + * error.c valid.c: working on better error reporting of validity + errors, especially providing an accurate context. + * result/valid/xlink.xml.err result/valid/rss.xml.err: better + error reports in those cases. + Thu Sep 5 13:29:47 CEST 2002 Daniel Veillard * DOCBparser.c HTMLparser.c c14n.c entities.c list.c diff --git a/error.c b/error.c index 14d91f31..9a80fd5e 100644 --- a/error.c +++ b/error.c @@ -350,22 +350,34 @@ xmlParserValidityError(void *ctx, const char *msg, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; + int len = xmlStrlen((const xmlChar *) msg); + static int had_info = 0; + int need_context = 0; + int need_info = 0; - if (ctxt != NULL) { - input = ctxt->input; - if ((input->filename == NULL) && (ctxt->inputNr > 1)) - input = ctxt->inputTab[ctxt->inputNr - 2]; - - xmlParserPrintFileInfo(input); + if ((len > 1) && (msg[len - 2] != ':')) { + if (ctxt != NULL) { + input = ctxt->input; + if ((input->filename == NULL) && (ctxt->inputNr > 1)) + input = ctxt->inputTab[ctxt->inputNr - 2]; + + if (had_info == 0) { + xmlParserPrintFileInfo(input); + } + } + xmlGenericError(xmlGenericErrorContext, "validity error: "); + need_context = 1; + had_info = 0; + } else { + had_info = 1; } - xmlGenericError(xmlGenericErrorContext, "validity error: "); XML_GET_VAR_STR(msg, str); xmlGenericError(xmlGenericErrorContext, "%s", str); if (str != NULL) xmlFree(str); - if (ctxt != NULL) { + if ((ctxt != NULL) && (input != NULL)) { xmlParserPrintFileContext(input); } } @@ -385,8 +397,9 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; + int len = xmlStrlen((const xmlChar *) msg); - if (ctxt != NULL) { + if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { input = ctxt->input; if ((input->filename == NULL) && (ctxt->inputNr > 1)) input = ctxt->inputTab[ctxt->inputNr - 2]; diff --git a/result/valid/rss.xml.err b/result/valid/rss.xml.err index f76367dc..1a998f20 100644 --- a/result/valid/rss.xml.err +++ b/result/valid/rss.xml.err @@ -1,3 +1,3 @@ -./test/valid/rss.xml:177: validity error: Element rss does not carry attribute version +./test/valid/rss.xml:172: validity error: Element rss does not carry attribute version ^ diff --git a/result/valid/xlink.xml.err b/result/valid/xlink.xml.err index 27977f74..0394f194 100644 --- a/result/valid/xlink.xml.err +++ b/result/valid/xlink.xml.err @@ -1,6 +1,6 @@ ./test/valid/xlink.xml:450: validity error: ID dt-arc already defined

An arc is contained within an ^ -./test/valid/xlink.xml:530: validity error: IDREF attribute def references an unknown ID "dt-xlg" +./test/valid/xlink.xml:199: validity error: IDREF attribute def references an unknown ID "dt-xlg" ^ diff --git a/valid.c b/valid.c index 1e836d92..ca0d29d6 100644 --- a/valid.c +++ b/valid.c @@ -311,23 +311,27 @@ xmlValidStateDebug(xmlValidCtxtPtr ctxt) { #define VECTXT(ctxt, node) \ if ((ctxt != NULL) && (ctxt->error != NULL) && \ - (node != NULL) && (node->type == XML_ELEMENT_NODE)) { \ - if ((node->doc != NULL) && (node->doc->URL != NULL)) \ - ctxt->error(ctxt->userData, "%s:%d:", node->doc->URL,\ + (node != NULL)) { \ + xmlChar *base = xmlNodeGetBase(NULL,node); \ + if (base != NULL) { \ + ctxt->error(ctxt->userData, "%s:%d: ", base, \ (int) node->content); \ - else \ - ctxt->error(ctxt->userData, ":%d:", \ + xmlFree(base); \ + } else \ + ctxt->error(ctxt->userData, ":%d: ", \ (int) node->content); \ } #define VWCTXT(ctxt, node) \ if ((ctxt != NULL) && (ctxt->warning != NULL) && \ - (node != NULL) && (node->type == XML_ELEMENT_NODE)) { \ - if ((node->doc != NULL) && (node->doc->URL != NULL)) \ - ctxt->warning(ctxt->userData, "%s:%d:", node->doc->URL,\ + (node != NULL)) { \ + xmlChar *base = xmlNodeGetBase(NULL,node); \ + if (base != NULL) { \ + ctxt->warning(ctxt->userData, "%s:%d: ", base, \ (int) node->content); \ - else \ - ctxt->warning(ctxt->userData, ":%d:", \ + xmlFree(base); \ + } else \ + ctxt->warning(ctxt->userData, ":%d: ", \ (int) node->content); \ } @@ -1904,8 +1908,10 @@ xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value, /* * The id is already defined in this DTD. */ - if (ctxt != NULL) + if (ctxt != NULL) { + VECTXT(ctxt, attr->parent); VERROR(ctxt->userData, "ID %s already defined\n", value); + } xmlFreeID(ret); return(NULL); } @@ -4786,6 +4792,7 @@ xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) && (xmlStrEqual(root->name, BAD_CAST "html"))) goto name_ok; + VECTXT(ctxt, root); VERROR(ctxt->userData, "Not valid: root and DTD name do not match '%s' and '%s'\n", root->name, doc->intSubset->name); @@ -4874,6 +4881,7 @@ xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt, if (attr->atype == XML_ATTRIBUTE_IDREF) { id = xmlGetID(ctxt->doc, name); if (id == NULL) { + VECTXT(ctxt, attr->parent); VERROR(ctxt->userData, "IDREF attribute %s references an unknown ID \"%s\"\n", attr->name, name); @@ -4895,6 +4903,7 @@ xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt, *cur = 0; id = xmlGetID(ctxt->doc, str); if (id == NULL) { + VECTXT(ctxt, attr->parent); VERROR(ctxt->userData, "IDREFS attribute %s references an unknown ID \"%s\"\n", attr->name, str);