
[[[

Print error codes in error messages.

Proposed by Karl in http://svn.haxx.se/dev/archive-2008-02/0084.shtml
after he suddenly discovered google et al:

  Now that there are search engines, it's possibly an argument for
  including the error code itself in error messages (even though that's
  always been held up as one of those ridiculous things engineers do
  that users hate).  So:
  
     "Commit failed due to blah blah blah ... (svn error 26754)"
  
  I'm making up the syntax, but you get the idea.  People could search
  for "svn error 26754" and presumably get helpful hits, and this would
  remain stable even when we change the human-readable part of the error
  message.

* subversion/libsvn_subr/error.c
  (SVN_FILE_LINE_UNDEFINED): Include a colon here that used to
    be printed along with a format string which was removed.
  (print_error): Append APR error code along with all error messages.

* subversion/tests/cmdline/switch_tests.py
  (commit_routine_switching, forced_switch_failures): Fix these tests,
   they were broken by the changes made to libsvn_subr/error.c.

* subversion/tests/cmdline/diff_tests.py
  (diff_non_version_controlled_file): ditto

* subversion/tests/cmdline/prop_tests.py
  (inappropriate_props): ditto

* subversion/tests/cmdline/commit_tests.py
  (set_invalid_revprops, start_commit_hook_test, pre_commit_hook_test): ditto

* subversion/tests/cmdline/checkout_tests.py
  (co_with_obstructing_local_adds): ditto
]]]

Index: subversion/libsvn_subr/error.c
===================================================================
--- subversion/libsvn_subr/error.c	(revision 29173)
+++ subversion/libsvn_subr/error.c	(working copy)
@@ -30,7 +30,7 @@
 
 #ifdef SVN_DEBUG
 /* file_line for the non-debug case. */
-static const char SVN_FILE_LINE_UNDEFINED[] = "svn:<undefined>";
+static const char SVN_FILE_LINE_UNDEFINED[] = "svn:<undefined>: ";
 #endif /* SVN_DEBUG */
 
 #include "svn_private_config.h"
@@ -314,23 +314,21 @@ print_error(svn_error_t *err, FILE *stre
       && !(temp_err = svn_utf_cstring_to_utf8(&file_utf8, err->file,
                                               err->pool)))
     svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
-                                        "%s:%ld", err->file, err->line));
+                                        "%s:%ld: ", err->file, err->line));
   else
     {
       svn_error_clear(svn_cmdline_fputs(SVN_FILE_LINE_UNDEFINED,
                                         stream, err->pool));
       svn_error_clear(temp_err);
     }
-
-  svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
-                                      ": (apr_err=%d)\n", err->apr_err));
 #endif /* SVN_DEBUG */
 
   /* Only print the same APR error string once. */
   if (err->message)
     {
-      svn_error_clear(svn_cmdline_fprintf(stream, err->pool, "%s%s\n",
-                                          prefix, err->message));
+      svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
+                                          "%s%s (svn error %d)\n",
+                                          prefix, err->message, err->apr_err));
     }
   else
     {
@@ -348,7 +346,8 @@ print_error(svn_error_t *err, FILE *stre
         }
 
       svn_error_clear(svn_cmdline_fprintf(stream, err->pool,
-                                          "%s%s\n", prefix, err_string));
+                                          "%s%s (svn error %d)\n",
+                                          prefix, err_string, err->apr_err));
     }
 }
 
Index: subversion/tests/cmdline/switch_tests.py
===================================================================
--- subversion/tests/cmdline/switch_tests.py	(revision 29173)
+++ subversion/tests/cmdline/switch_tests.py	(working copy)
@@ -180,7 +180,7 @@ def commit_routine_switching(wc_dir, ver
   # same URL.  We don't allow this.
   svntest.actions.run_and_verify_commit(
     wc_dir, None, None,
-    "svn: Cannot commit both .* as they refer to the same URL$",
+    "svn: Cannot commit both .* as they refer to the same URL.*",
     wc_dir)
 
   # Okay, that all taken care of, let's revert the A/D/G/pi path and
@@ -1239,7 +1239,7 @@ def forced_switch_failures(sbox):
                                         None, None, None,
                                         ".*Failed to add directory .*" + \
                                         ": a non-directory object of the" + \
-                                        " same name already exists\n",
+                                        " same name already exists.*\n",
                                         None, None, None, None, 0, '--force')
 
   # 2) A forced switch that tries to add a dir when a file of the same
@@ -1251,7 +1251,7 @@ def forced_switch_failures(sbox):
                                         None, None, None,
                                         ".*Failed to add file .*" + \
                                         ": a non-file object of the " + \
-                                        "same name already exists\n",
+                                        "same name already exists.*\n",
                                         None, None, None, None, 0, '--force')
 
   # 3) A forced update that tries to add a directory when a versioned
@@ -1284,7 +1284,7 @@ def forced_switch_failures(sbox):
                                         ".*Failed to add " + \
                                         "directory .*: a versioned " + \
                                         "directory of the same name " + \
-                                        "already exists\n",
+                                        "already exists.*\n",
                                         None, None, None, None, 0, '--force')
 
 def switch_with_obstructing_local_adds(sbox):
Index: subversion/tests/cmdline/diff_tests.py
===================================================================
--- subversion/tests/cmdline/diff_tests.py	(revision 29173)
+++ subversion/tests/cmdline/diff_tests.py	(working copy)
@@ -542,7 +542,7 @@ def diff_non_version_controlled_file(sbo
   # there was a way to figure out if svn crashed, but all run_svn gives us is
   # the output, so here we are...
   for line in err_output:
-    if re.search("foo' is not under version control$", line):
+    if re.search("foo' is not under version control.*$", line):
       break
   else:
     raise svntest.Failure
Index: subversion/tests/cmdline/prop_tests.py
===================================================================
--- subversion/tests/cmdline/prop_tests.py	(revision 29173)
+++ subversion/tests/cmdline/prop_tests.py	(working copy)
@@ -667,12 +667,12 @@ def inappropriate_props(sbox):
 
   # ...grammatically incorrect
   svntest.actions.run_and_verify_svn('illegal grammar', None,
-                                     "svn: Pathname not terminated by ':'\n",
+                                     "svn: Pathname not terminated by ':'.*\n",
                                      'propset', SVN_PROP_MERGEINFO, '/trunk',
                                      path)
   svntest.actions.run_and_verify_svn('illegal grammar', None,
                                      "svn: Invalid revision number found "
-                                      "parsing 'one'\n",
+                                      "parsing 'one'.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/trunk:one', path)
 
@@ -680,20 +680,20 @@ def inappropriate_props(sbox):
   svntest.actions.run_and_verify_svn('overlapping ranges', None,
                                      "svn: Parsing of overlapping revision "
                                       "ranges '9-20' and '18-22' is not "
-                                      "supported\n",
+                                      "supported.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/branch:5-7,9-20,18-22', path)
 
   svntest.actions.run_and_verify_svn('overlapping ranges', None,
                                      "svn: Parsing of overlapping revision "
-                                      "ranges '3' and '3' is not supported\n",
+                                      "ranges '3' and '3' is not supported.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/branch:3,3', path)
 
   # ...contain unordered revision ranges
   svntest.actions.run_and_verify_svn('unordered ranges', None,
                                      "svn: Unable to parse unordered "
-                                      "revision ranges '5' and '2-3'\n",
+                                      "revision ranges '5' and '2-3'.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/featureX:5,2-3,9', path)
 
@@ -701,14 +701,14 @@ def inappropriate_props(sbox):
   #    equal to end revisions.
   svntest.actions.run_and_verify_svn('range start >= range end', None,
                                      "svn: Unable to parse reversed "
-                                      "revision range '20-5'\n",
+                                      "revision range '20-5'.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/featureX:4,20-5', path)
 
   # ...contain paths mapped to empty revision ranges
   svntest.actions.run_and_verify_svn('empty ranges', None,
                                      "svn: Mergeinfo for '/trunk' maps to "
-                                      "an empty revision range\n",
+                                      "an empty revision range.*\n",
                                      'propset', SVN_PROP_MERGEINFO,
                                      '/trunk:', path)
 
Index: subversion/tests/cmdline/commit_tests.py
===================================================================
--- subversion/tests/cmdline/commit_tests.py	(revision 29173)
+++ subversion/tests/cmdline/commit_tests.py	(working copy)
@@ -2242,7 +2242,7 @@ def set_invalid_revprops(sbox):
 
   # Empty revprop pair.
   svntest.actions.run_and_verify_svn(None, [],
-                                     'svn: Revision property pair is empty',
+                                     '.*svn: Revision property pair is empty.*',
                                      'mkdir', '-m', 'msg',
 				     '--with-revprop', '',
                                      remote_dir)
@@ -2285,7 +2285,7 @@ sys.exit(1)"""
   if len(actual_stderr) > 2:
     actual_stderr = actual_stderr[-2:]
   expected_stderr = [ "svn: " + hook_failure_message('start-commit'),
-                      "Start-commit hook failed\n"
+                      "Start-commit hook failed (svn error 165001)\n"
                     ]
   svntest.verify.compare_and_display_lines('Start-commit hook test',
                                            'STDERR',
@@ -2329,7 +2329,7 @@ sys.exit(1)"""
   if len(actual_stderr) > 2:
     actual_stderr = actual_stderr[-2:]
   expected_stderr = [ "svn: " + hook_failure_message('pre-commit'),
-                      "Pre-commit hook failed\n"
+                      "Pre-commit hook failed (svn error 165001)\n"
                     ]
   svntest.verify.compare_and_display_lines('Pre-commit hook test',
                                            'STDERR',
Index: subversion/tests/cmdline/checkout_tests.py
===================================================================
--- subversion/tests/cmdline/checkout_tests.py	(revision 29173)
+++ subversion/tests/cmdline/checkout_tests.py	(working copy)
@@ -683,7 +683,7 @@ def co_with_obstructing_local_adds(sbox)
                                                   D_path)
 
   test_stderr("svn: Failed to add directory '.*M': a versioned " \
-              "directory of the same name already exists\n", serr)
+              "directory of the same name already exists", serr)
 
   # --force shouldn't help either.
   sout, serr = svntest.actions.run_and_verify_svn("Checkout XPASS",
@@ -693,7 +693,7 @@ def co_with_obstructing_local_adds(sbox)
                                                   D_path, '--force')
 
   test_stderr("svn: Failed to add directory '.*M': a versioned " \
-              "directory of the same name already exists\n", serr)
+              "directory of the same name already exists", serr)
 
   # Try to co omicron's parent.
   sout, serr = svntest.actions.run_and_verify_svn("Checkout XPASS",
@@ -703,7 +703,7 @@ def co_with_obstructing_local_adds(sbox)
                                                   F_path)
 
   test_stderr("svn: Failed to add file '.*omicron': a file of the same " \
-              "name is already scheduled for addition with history\n", serr)
+              "name is already scheduled for addition with history", serr)
 
   # Again, --force shouldn't matter.
   sout, serr = svntest.actions.run_and_verify_svn("Checkout XPASS",
@@ -713,7 +713,7 @@ def co_with_obstructing_local_adds(sbox)
                                                   F_path, '--force')
 
   test_stderr("svn: Failed to add file '.*omicron': a file of the same " \
-              "name is already scheduled for addition with history\n", serr)
+              "name is already scheduled for addition with history", serr)
 
 #----------------------------------------------------------------------
 

