[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Include offending XML in "Malformed XML" error message

From: Charles Bailey <bailey.charles_at_gmail.com>
Date: 2005-02-27 00:20:28 CET

On Thu, 24 Feb 2005 14:17:20 +0100 (CET), Peter N. Lundblad
<peter@famlundblad.se> wrote:
> On Wed, 23 Feb 2005, Charles Bailey wrote:
>
> > Attached is a patchlet that, when expat fails to parse an hunk of XML,
> > appends at least part of the offending hunk to the error message. It
> > provides a better jumping-off point for further debugging than the
> > current message, especially since the line number often isn't all that
> > meaningful. It's not intended to flag the error specifically, or even
> > to insure it's actually in the output fragment, since it'd be too hard
> > to reliably identify the problem. (For that matter, I can envision
> > cases where the error is actually in a previously parsed hunk of XML,
> > but doesn't become apparent until a tag mismatches in the current hunk
> > or the like.) By way of example, the current error message:
> >
> I think your approach is good enough in this respect.
>
> > A few comments:

> We generally try to avoid line breaks in error messages. That's because of
> GUI issues. But with l10n and long filenames, we can't possibly keep
> messages within 80 chars. IN this case, I think it is a good idea to keep
> the newline befre the XML.

> > - I placed delimiters before and after the XML with the thought that
> > it might help in some
> > situations where the XML itself started with odd characters; again,
> > this is relatively
> > arbitrary. It'd arguably be of some help for parsing the error
> > (the delimiters aren't
> > legal XML), but as this is a fatal and (one hopes) uncommon error,
> > I don't think many
> > people will be writing tools to anticipate it. If the consensus is
> > that they just add noise,
> > they're easy enough to drop.
> >
> IMO, just drop them.

OK, as 1 of 1 respondents recommends dropping them, they're gone.

> Good start:-) A few commets below. (Also, could you please try to get the
> MIME type of your attachments as some text mime type Makes it easier to
> review.)

Definitely. I put a little too much faith in the mail client's
ability to recognize text; for now, I'll just inline the patch, since
it's small.

>> Display fragment of offending XML on "Malformed XML" error
>
> Missing period at end of sentence and blank line after the summary.
>
> * subversion/libsvn_subr/xml.c
> (svn_xml_parse): Append reasonable hunk of XML to error message
>
> We usually put the asterisk in the first column.

OK -- I overtrained on incidental details in HACKING.

> + _("Malformed XML: %s at line %d; XML %s:\n>>>>>\n%.240s\n<<<<<\n"),
> Drop the trailing newline.
> XML_ErrorString (XML_GetErrorCode (svn_parser->parser)),
> - XML_GetCurrentLineNumber (svn_parser->parser));
> + XML_GetCurrentLineNumber (svn_parser->parser),
> + len > 240 ? "starts" : "is", buf);
> You can't use message fragment like this in internationalized messages.
> Think of what happens when the _() marked string gets translated, but no
> the "is" or "starts":-) You have tomove the condition outside the message,
> creating two complete messages instead.

OK -- my oversight. Sorry. The problem's really not worth two
messages, so I'll just use "starts"; some small fraction of the time
the offending XML may coincidentally also end with the displayerd
fragment.

A revised patch is appended below my sig, with appropriate attention
to l10n. I've taken idiom from other messages where I can (z.B.
'beginnen' v. 'anfingen'). More fluent readers may want to pitch in
on the middle European and Scandinavian languages, where my morphology
may be laughably in error, and I've punted almost entirely on the east
Asian languages, but I hope it'll serve as a decent start nonetheless.

--
Regards,
Charles Bailey
Lists: bailey _dot_ charles _at_ gmail _dot_ com
Other: bailey _at_ newman _dot_ upenn _dot_ edu
Display XML fragment in "Malformed XML" error message to aid debugging.
* subversion/libsvn_subr/xml.c
  (svn_xml_parse): Append reasonable hunk of XML to error message
* subversion/po/de.po,
  subversion/po/es.po,
  subversion/po/ja.po,
  subversion/po/ko.po,
  subversion/po/nb.po,
  subversion/po/pl.po,
  subversion/po/pt_BR.po,
  subversion/po/sv.po,
  subversion/po/zh_CN.po,
  subversion/po/zh_CN.po:
  Update error message.
Index: subversion/libsvn_subr/xml.c
===================================================================
--- subversion/libsvn_subr/xml.c	(revision 13160)
+++ subversion/libsvn_subr/xml.c	(working copy)
@@ -417,9 +417,9 @@
     {
       err = svn_error_createf
         (SVN_ERR_XML_MALFORMED, NULL, 
-         _("Malformed XML: %s at line %d"),
+         _("Malformed XML: %s at line %d; XML starts:\n%.240s"),
          XML_ErrorString (XML_GetErrorCode (svn_parser->parser)),
-         XML_GetCurrentLineNumber (svn_parser->parser));
+         XML_GetCurrentLineNumber (svn_parser->parser), buf);
       
       /* Kill all parsers and return the expat error */
       svn_xml_free_parser (svn_parser);
Index: subversion/po/pt_BR.po
===================================================================
--- subversion/po/pt_BR.po	(revision 13160)
+++ subversion/po/pt_BR.po	(working copy)
@@ -4943,8 +4943,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "XML mal formado: %s na linha %d"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "XML mal formado: %s na linha %d; XML começa:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/es.po
===================================================================
--- subversion/po/es.po	(revision 13160)
+++ subversion/po/es.po	(working copy)
@@ -5011,8 +5011,8 @@
 
 #: libsvn_subr/xml.c:420
 #, fuzzy, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "Datos de flujo malformados"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "Datos de XML malformados: %s en línea %d; XML comienza:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/sv.po
===================================================================
--- subversion/po/sv.po	(revision 13160)
+++ subversion/po/sv.po	(working copy)
@@ -4930,8 +4930,8 @@
 
 #: libsvn_subr/xml.c:367
 #, fuzzy, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "Felaktig data i ström"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "Felaktig data i ström: %s vid rad %d; XML starta:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/de.po
===================================================================
--- subversion/po/de.po	(revision 13160)
+++ subversion/po/de.po	(working copy)
@@ -5006,8 +5006,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "Fehlerhaftes XML: %s in Zeile %d"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "Fehlerhaftes XML: %s in Zeile %d; XML beginnt:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/ko.po
===================================================================
--- subversion/po/ko.po	(revision 13160)
+++ subversion/po/ko.po	(working copy)
@@ -4882,8 +4882,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "잘못된 XML: %s (줄 번호 %d)"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "잘못된 XML: %s (줄 번호 %d); XML:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/ja.po
===================================================================
--- subversion/po/ja.po	(revision 13160)
+++ subversion/po/ja.po	(working copy)
@@ -5262,8 +5262,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "異常な XML です: %s (行 %d)"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "異常な XML です: %s (行 %d); XML:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/zh_TW.po
===================================================================
--- subversion/po/zh_TW.po	(revision 13160)
+++ subversion/po/zh_TW.po	(working copy)
@@ -4890,8 +4890,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "有缺陷 XML: %s 於第 %d 列"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "有缺陷 XML: %s 於第 %d 列; XML:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/pl.po
===================================================================
--- subversion/po/pl.po	(revision 13160)
+++ subversion/po/pl.po	(working copy)
@@ -5054,8 +5054,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "Uszkodzony XML: %s w linii %d"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "Uszkodzony XML: %s w linii %d; XML wersja:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/nb.po
===================================================================
--- subversion/po/nb.po	(revision 13160)
+++ subversion/po/nb.po	(working copy)
@@ -4935,8 +4935,8 @@
 
 #: libsvn_subr/xml.c:420
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "Misdannet XML: %s i linje %d"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "Misdannet XML: %s i linje %d; XML starter:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
Index: subversion/po/zh_CN.po
===================================================================
--- subversion/po/zh_CN.po	(revision 13160)
+++ subversion/po/zh_CN.po	(working copy)
@@ -4805,8 +4805,8 @@
 
 #: libsvn_subr/xml.c:367
 #, c-format
-msgid "Malformed XML: %s at line %d"
-msgstr "畸形的XML:%s 在第 %d 行"
+msgid "Malformed XML: %s at line %d; XML starts:\n%.240s"
+msgstr "畸形的XML:%s 在第 %d 行; XML:\n%.240s"
 
 #: libsvn_wc/adm_crawler.c:374
 #, c-format
  
## End of patch ##
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sun Feb 27 00:21:37 2005

This is an archived mail posted to the Subversion Dev mailing list.