You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2012/10/16 13:34:35 UTC

svn commit: r1398742 - in /subversion/trunk/subversion/libsvn_ra_serf: ra_serf.h replay.c sb_bucket.c serf.c update.c util.c util_error.c

Author: ivan
Date: Tue Oct 16 11:34:35 2012
New Revision: 1398742

URL: http://svn.apache.org/viewvc?rev=1398742&view=rev
Log:
Use serf_error_string() function to get serf error code description 
message. This avoids cryptic error messages "APR does not understand this 
error code".

* subversion/libsvn_ra_serf/replay.c
* subversion/libsvn_ra_serf/sb_bucket.c
* subversion/libsvn_ra_serf/serf.c
* subversion/libsvn_ra_serf/update.c
* subversion/libsvn_ra_serf/util.c
  (svn_ra_serf__replay_range, svn_ra_serf__copy_into_spillbuf,
   load_config, svn_ra_serf__open, handle_fetch, handle_stream, 
   open_connection_if_needed, finish_report, svn_ra_serf__context_run_wait,
   svn_ra_serf__handle_discard_body, handle_server_error,
   svn_ra_serf__handle_xml_parser, handle_response,
   expat_response_handler): Use svn_ra_serf__wrap_err() 
   instead of svn_error_wrap_apr().

* subversion/libsvn_ra_serf/ra_serf.h
* subversion/libsvn_ra_serf/util_error.c
  (svn_ra_serf__wrap_err): New.

Added:
    subversion/trunk/subversion/libsvn_ra_serf/util_error.c   (with props)
Modified:
    subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
    subversion/trunk/subversion/libsvn_ra_serf/replay.c
    subversion/trunk/subversion/libsvn_ra_serf/sb_bucket.c
    subversion/trunk/subversion/libsvn_ra_serf/serf.c
    subversion/trunk/subversion/libsvn_ra_serf/update.c
    subversion/trunk/subversion/libsvn_ra_serf/util.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h Tue Oct 16 11:34:35 2012
@@ -1719,6 +1719,21 @@ svn_ra_serf__create_sb_bucket(svn_spillb
                               apr_pool_t *result_pool,
                               apr_pool_t *scratch_pool);
 
+/** Wrap STATUS from an serf function. If STATUS is not serf error code,
+  * this is equivalent to svn_error_wrap_apr().
+ */
+svn_error_t *
+svn_ra_serf__wrap_err(apr_status_t status,
+                      const char *fmt,
+                      ...);
+
+
+#if defined(SVN_DEBUG)
+/* Wrapper macros to collect file and line information */
+#define svn_ra_serf__wrap_err \
+  (svn_error__locate(__FILE__,__LINE__), (svn_ra_serf__wrap_err))
+
+#endif
 
 #ifdef __cplusplus
 }

Modified: subversion/trunk/subversion/libsvn_ra_serf/replay.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/replay.c?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/replay.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/replay.c Tue Oct 16 11:34:35 2012
@@ -904,9 +904,8 @@ svn_ra_serf__replay_range(svn_ra_session
       SVN_ERR(err);
       if (status)
         {
-          return svn_error_wrap_apr(status,
-                                    _("Error retrieving replay REPORT (%d)"),
-                                    status);
+          return svn_ra_serf__wrap_err(status,
+                                       _("Error retrieving replay REPORT"));
         }
       done_reports = NULL;
     }

Modified: subversion/trunk/subversion/libsvn_ra_serf/sb_bucket.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/sb_bucket.c?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/sb_bucket.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/sb_bucket.c Tue Oct 16 11:34:35 2012
@@ -62,7 +62,7 @@ svn_ra_serf__copy_into_spillbuf(svn_spil
       status = serf_bucket_read(bkt, SERF_READ_ALL_AVAIL, &data, &len);
 
       if (status != APR_SUCCESS && status != APR_EOF)
-        return svn_error_wrap_apr(status, _("Failed to read the request"));
+        return svn_ra_serf__wrap_err(status, _("Failed to read the request"));
 
       SVN_ERR(svn_spillbuf__write(*spillbuf, data, len, scratch_pool));
 

Modified: subversion/trunk/subversion/libsvn_ra_serf/serf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/serf.c?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/serf.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/serf.c Tue Oct 16 11:34:35 2012
@@ -307,9 +307,9 @@ load_config(svn_ra_serf__session_t *sess
                                      session->pool);
       if (status)
         {
-          return svn_error_wrap_apr(status,
-                                    _("Could not resolve proxy server '%s'"),
-                                    proxy_host);
+          return svn_ra_serf__wrap_err(
+                   status, _("Could not resolve proxy server '%s'"),
+                   proxy_host);
         }
       session->using_proxy = TRUE;
       serf_config_proxy(session->context, proxy_addr);
@@ -431,7 +431,7 @@ svn_ra_serf__open(svn_ra_session_t *sess
                             svn_ra_serf__conn_closed, serf_sess->conns[0],
                             serf_sess->pool);
   if (status)
-    return svn_error_wrap_apr(status, NULL);
+    return svn_ra_serf__wrap_err(status, NULL);
 
   /* Set the progress callback. */
   serf_context_set_progress_cb(serf_sess->context, svn_ra_serf__progress,

Modified: subversion/trunk/subversion/libsvn_ra_serf/update.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/update.c?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/update.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/update.c Tue Oct 16 11:34:35 2012
@@ -979,7 +979,7 @@ handle_fetch(serf_request_t *request,
       status = serf_bucket_read(response, 8000, &data, &len);
       if (SERF_BUCKET_READ_ERROR(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
 
       fetch_ctx->read_size += len;
@@ -999,7 +999,7 @@ handle_fetch(serf_request_t *request,
               /* Skip on to the next iteration of this loop. */
               if (APR_STATUS_IS_EAGAIN(status))
                 {
-                  return svn_error_wrap_apr(status, NULL);
+                  return svn_ra_serf__wrap_err(status, NULL);
                 }
               continue;
             }
@@ -1075,11 +1075,11 @@ handle_fetch(serf_request_t *request,
           svn_pool_destroy(info->pool);
 
           if (status)
-            return svn_error_wrap_apr(status, NULL);
+            return svn_ra_serf__wrap_err(status, NULL);
         }
       if (APR_STATUS_IS_EAGAIN(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
     }
   /* not reached */
@@ -1121,7 +1121,7 @@ handle_stream(serf_request_t *request,
       status = serf_bucket_read(response, 8000, &data, &len);
       if (SERF_BUCKET_READ_ERROR(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
 
       fetch_ctx->read_size += len;
@@ -1140,7 +1140,7 @@ handle_stream(serf_request_t *request,
               /* Skip on to the next iteration of this loop. */
               if (APR_STATUS_IS_EAGAIN(status))
                 {
-                  return svn_error_wrap_apr(status, NULL);
+                  return svn_ra_serf__wrap_err(status, NULL);
                 }
               continue;
             }
@@ -1170,7 +1170,7 @@ handle_stream(serf_request_t *request,
 
       if (status)
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
     }
   /* not reached */
@@ -2338,7 +2338,7 @@ open_connection_if_needed(svn_ra_serf__s
                                        sess->conns[cur],
                                        sess->pool);
       if (status)
-        return svn_error_wrap_apr(status, NULL);
+        return svn_ra_serf__wrap_err(status, NULL);
 
       sess->num_conns++;
     }
@@ -2515,8 +2515,7 @@ finish_report(void *report_baton,
       SVN_ERR(err);
       if (status)
         {
-          return svn_error_wrap_apr(status, _("Error retrieving REPORT (%d)"),
-                                    status);
+          return svn_ra_serf__wrap_err(status, _("Error retrieving REPORT"));
         }
 
       /* Open extra connections if we have enough requests to send. */

Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1398742&r1=1398741&r2=1398742&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/util.c Tue Oct 16 11:34:35 2012
@@ -770,7 +770,7 @@ svn_ra_serf__context_run_wait(svn_boolea
                         _("Error running context"));
             }
 
-          return svn_error_wrap_apr(status, _("Error running context"));
+          return svn_ra_serf__wrap_err(status, _("Error running context"));
         }
 
       /* Debugging purposes only! */
@@ -953,7 +953,7 @@ svn_ra_serf__handle_discard_body(serf_re
 
   status = drain_bucket(response);
   if (status)
-    return svn_error_wrap_apr(status, NULL);
+    return svn_ra_serf__wrap_err(status, NULL);
 
   return SVN_NO_ERROR;
 }
@@ -1492,7 +1492,7 @@ handle_server_error(serf_request_t *requ
      surface. */
   err = drain_bucket(response);
   if (err && !SERF_BUCKET_READ_ERROR(err))
-    return svn_error_wrap_apr(err, NULL);
+    return svn_ra_serf__wrap_err(err, NULL);
 
   return SVN_NO_ERROR;
 }
@@ -1514,7 +1514,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
   status = serf_bucket_response_status(response, &sl);
   if (SERF_BUCKET_READ_ERROR(status))
     {
-      return svn_error_wrap_apr(status, NULL);
+      return svn_ra_serf__wrap_err(status, NULL);
     }
 
   /* Woo-hoo.  Nothing here to see.  */
@@ -1566,7 +1566,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
 
       if (SERF_BUCKET_READ_ERROR(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
 
       ctx->read_size += len;
@@ -1587,7 +1587,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
               /* Skip on to the next iteration of this loop. */
               if (APR_STATUS_IS_EAGAIN(status))
                 {
-                  return svn_error_wrap_apr(status, NULL);
+                  return svn_ra_serf__wrap_err(status, NULL);
                 }
               continue;
             }
@@ -1631,7 +1631,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
 
       if (APR_STATUS_IS_EAGAIN(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
 
       if (APR_STATUS_IS_EOF(status))
@@ -1652,7 +1652,7 @@ svn_ra_serf__handle_xml_parser(serf_requ
               add_done_item(ctx);
             }
 
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
 
       /* feed me! */
@@ -1842,7 +1842,7 @@ handle_response(serf_request_t *request,
           && handler->sline.code != 304)
         {
           err = svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA,
-                                  svn_error_wrap_apr(status, NULL),
+                                  svn_ra_serf__wrap_err(status, NULL),
                                   _("Premature EOF seen from server"
                                     " (http status=%d)"),
                                   handler->sline.code);
@@ -2444,7 +2444,7 @@ expat_response_handler(serf_request_t *r
 
       status = serf_bucket_read(response, PARSE_CHUNK_SIZE, &data, &len);
       if (SERF_BUCKET_READ_ERROR(status))
-        return svn_error_wrap_apr(status, NULL);
+        return svn_ra_serf__wrap_err(status, NULL);
 
 #if 0
       /* ### move restart/skip into the core handler  */
@@ -2498,7 +2498,7 @@ expat_response_handler(serf_request_t *r
 
       if (status && !SERF_BUCKET_READ_ERROR(status))
         {
-          return svn_error_wrap_apr(status, NULL);
+          return svn_ra_serf__wrap_err(status, NULL);
         }
     }
 

Added: subversion/trunk/subversion/libsvn_ra_serf/util_error.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util_error.c?rev=1398742&view=auto
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/util_error.c (added)
+++ subversion/trunk/subversion/libsvn_ra_serf/util_error.c Tue Oct 16 11:34:35 2012
@@ -0,0 +1,91 @@
+/*
+ * util_error.c : serf utility routines for wrapping serf status codes
+ *
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ */
+#include <serf.h>
+
+#include "svn_utf.h"
+#include "private/svn_error_private.h"
+
+/*
+ * Undefine the helpers for creating errors.
+ *
+ * *NOTE*: Any use of these functions in any other function may need
+ * to call svn_error__locate() because the macro that would otherwise
+ * do this is being undefined and the filename and line number will
+ * not be properly set in the static error_file and error_line
+ * variables.
+ */
+#undef svn_error_create
+#undef svn_error_createf
+#undef svn_error_quick_wrap
+#undef svn_error_wrap_apr
+#undef svn_ra_serf__wrap_err
+
+svn_error_t *
+svn_ra_serf__wrap_err(apr_status_t status,
+                      const char *fmt,
+                      ...)
+{
+  const char *serf_err_msg = serf_error_string(status);
+  svn_error_t *err;
+  va_list ap;
+
+  err = svn_error_create(status, NULL, NULL);
+
+  if (serf_err_msg || fmt)
+    {
+      const char *msg;
+      const char *err_msg;
+      char errbuf[255]; /* Buffer for APR error message. */
+
+      if (serf_err_msg)
+        {
+          err_msg = serf_err_msg;
+        }
+      else
+        {
+          svn_error_t *utf8_err;
+
+          /* Grab the APR error message. */
+          apr_strerror(status, errbuf, sizeof(errbuf));
+          utf8_err = svn_utf_cstring_to_utf8(&err_msg, errbuf, err->pool);
+          if (utf8_err)
+            err_msg = NULL;
+          svn_error_clear(utf8_err);
+        }
+
+      /* Append it to the formatted message. */
+      va_start(ap, fmt);
+      msg = apr_pvsprintf(err->pool, fmt, ap);
+      va_end(ap);
+      if (err_msg)
+        {
+          err->message = apr_pstrcat(err->pool, msg, ": ", err_msg, NULL);
+        }
+      else
+        {
+          err->message = msg;
+        }
+    }
+
+  return err;
+}

Propchange: subversion/trunk/subversion/libsvn_ra_serf/util_error.c
------------------------------------------------------------------------------
    svn:eol-style = native