Author: danielsh
Date: Thu Apr  4 14:36:13 2013
New Revision: 1464570

URL: http://svn.apache.org/r1464570
Log:
Implement which-error.py in C.

* subversion/include/svn_error.h
  (svn_error_symbolic_name): Declare new API.

* subversion/include/svn_error_codes.h
  (SVN_ERROR_START, SVN_ERRDEF, SVN_ERROR_END):
    Include the error name as a string, in SVN_ERROR_BUILD_ARRAY mode only.

* subversion/libsvn_subr/error.c
  (struct err_defn): Add a member, also add comments.
  (svn_error_symbolic_name): Implement new API.

* subversion/tests/libsvn_subr/error-test.c
  (test_error_symbolic_name): New test.
  (test_funcs): Run it, passing.

Modified:
    subversion/trunk/subversion/include/svn_error.h
    subversion/trunk/subversion/include/svn_error_codes.h
    subversion/trunk/subversion/libsvn_subr/error.c
    subversion/trunk/subversion/tests/libsvn_subr/error-test.c

Modified: subversion/trunk/subversion/include/svn_error.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error.h?rev=1464570&r1=1464569&r2=1464570&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error.h (original)
+++ subversion/trunk/subversion/include/svn_error.h Thu Apr  4 14:36:13 2013
@@ -66,6 +66,20 @@ svn_strerror(apr_status_t statcode,
              apr_size_t bufsize);
 
 
+/**
+ * Return the symbolic name of an error code.  If the error code
+ * is not a Subversion error code (from svn_error_codes.h), return @c NULL.
+ *
+ * @note In rare cases, a single numeric code has more than one symbolic name.
+ * (For example, #SVN_ERR_WC_NOT_DIRECTORY and #SVN_ERR_WC_NOT_WORKING_COPY).
+ * In those cases, it is not guaranteed which symbolic name is returned.
+ *
+ * @since New in 1.8.
+ */
+const char *
+svn_error_symbolic_name(apr_status_t statcode);
+
+
 /** If @a err has a custom error message, return that, otherwise
  * store the generic error string associated with @a err->apr_err into
  * @a buf (terminating with NULL) and return @a buf.

Modified: subversion/trunk/subversion/include/svn_error_codes.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error_codes.h?rev=1464570&r1=1464569&r2=1464570&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error_codes.h (original)
+++ subversion/trunk/subversion/include/svn_error_codes.h Thu Apr  4 14:36:13 
2013
@@ -63,9 +63,9 @@ extern "C" {
 
 #define SVN_ERROR_START \
         static const err_defn error_table[] = { \
-          { SVN_WARNING, "Warning" },
-#define SVN_ERRDEF(num, offset, str) { num, str },
-#define SVN_ERROR_END { 0, NULL } };
+          { SVN_WARNING, "SVN_WARNING", "Warning" },
+#define SVN_ERRDEF(num, offset, str) { num, #num, str },
+#define SVN_ERROR_END { 0, NULL, NULL } };
 
 #elif !defined(SVN_ERROR_ENUM_DEFINED)
 

Modified: subversion/trunk/subversion/libsvn_subr/error.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/error.c?rev=1464570&r1=1464569&r2=1464570&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/error.c (original)
+++ subversion/trunk/subversion/libsvn_subr/error.c Thu Apr  4 14:36:13 2013
@@ -631,8 +631,9 @@ svn_err_best_message(svn_error_t *err, c
 /* svn_strerror() and helpers */
 
 typedef struct err_defn {
-  svn_errno_t errcode;
-  const char *errdesc;
+  svn_errno_t errcode; /* 160004 */
+  const char *errname; /* SVN_ERR_FS_CORRUPT */
+  const char *errdesc; /* default message */
 } err_defn;
 
 /* To understand what is going on here, read svn_error_codes.h. */
@@ -654,6 +655,23 @@ svn_strerror(apr_status_t statcode, char
   return apr_strerror(statcode, buf, bufsize);
 }
 
+const char *
+svn_error_symbolic_name(apr_status_t statcode)
+{
+  const err_defn *defn;
+
+  for (defn = error_table; defn->errdesc != NULL; ++defn)
+    if (defn->errcode == (svn_errno_t)statcode)
+      return defn->errname;
+
+  /* "No error" is not in error_table. */
+  if (statcode == SVN_NO_ERROR)
+    return "SVN_NO_ERROR";
+
+  return NULL;
+}
+
+
 
 /* Malfunctions. */
 

Modified: subversion/trunk/subversion/tests/libsvn_subr/error-test.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/error-test.c?rev=1464570&r1=1464569&r2=1464570&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/error-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/error-test.c Thu Apr  4 
14:36:13 2013
@@ -182,6 +182,46 @@ test_error_purge_tracing(apr_pool_t *poo
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_error_symbolic_name(apr_pool_t *pool)
+{
+  struct {
+    svn_errno_t errcode;
+    const char *errname;
+  } errors[] = {
+    { SVN_ERR_BAD_CONTAINING_POOL, "SVN_ERR_BAD_CONTAINING_POOL" },
+    { SVN_ERR_BAD_FILENAME, "SVN_ERR_BAD_FILENAME" },
+    { SVN_ERR_XML_ATTRIB_NOT_FOUND, "SVN_ERR_XML_ATTRIB_NOT_FOUND" },
+    { SVN_ERR_ENTRY_NOT_FOUND, "SVN_ERR_ENTRY_NOT_FOUND" },
+    { SVN_ERR_ENTRY_CATEGORY_START + 1, NULL }, /* unused slot */
+    { SVN_ERR_ENTRY_EXISTS, "SVN_ERR_ENTRY_EXISTS" },
+    { SVN_ERR_ASSERTION_ONLY_TRACING_LINKS, 
"SVN_ERR_ASSERTION_ONLY_TRACING_LINKS" },
+    { SVN_ERR_FS_CORRUPT, "SVN_ERR_FS_CORRUPT" },
+    /* The following two error codes can return either of their names
+       as the string. For simplicity, test what the current implementation
+       returns; but if it starts returning "SVN_ERR_WC_NOT_WORKING_COPY",
+       that's fine (and permitted by the API contract). */
+    { SVN_ERR_WC_NOT_DIRECTORY, "SVN_ERR_WC_NOT_WORKING_COPY" },
+    { SVN_ERR_WC_NOT_WORKING_COPY, "SVN_ERR_WC_NOT_WORKING_COPY" },
+    /* Test an implementation detail. */
+    { SVN_ERR_BAD_CATEGORY_START, "SVN_ERR_BAD_CONTAINING_POOL" },
+    /* Test non-errors. */
+    { 1, NULL },
+    { SVN_ERR_WC_CATEGORY_START - 1, NULL },
+    /* Whitebox-test exceptional cases. */
+    { SVN_WARNING, "SVN_WARNING" },
+    { 0, "SVN_NO_ERROR" }
+    /* No sentinel. */
+  };
+  int i;
+
+  for (i = 0; i < sizeof(errors) / sizeof(errors[0]); i++)
+    SVN_TEST_STRING_ASSERT(svn_error_symbolic_name(errors[i].errcode),
+                           errors[i].errname);
+
+  return SVN_NO_ERROR;
+}
+
 
 /* The test table.  */
 
@@ -192,5 +232,7 @@ struct svn_test_descriptor_t test_funcs[
                    "test svn_error_root_cause"),
     SVN_TEST_PASS2(test_error_purge_tracing,
                    "test svn_error_purge_tracing"),
+    SVN_TEST_PASS2(test_error_symbolic_name,
+                   "test svn_error_symbolic_name"),
     SVN_TEST_NULL
   };


Reply via email to