Patchwork [2,of,5] lfs: provide more Batch API error info via a hint in the raised exception

login
register
mail settings
Submitter Matt Harbison
Date Nov. 16, 2018, 2:53 a.m.
Message ID <872ad0231ff2b33efe2a.1542336831@Envy>
Download mbox | patch
Permalink /patch/36619/
State Accepted
Headers show

Comments

Matt Harbison - Nov. 16, 2018, 2:53 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1542322501 18000
#      Thu Nov 15 17:55:01 2018 -0500
# Node ID 872ad0231ff2b33efe2a66a919221b89320b0f7e
# Parent  932374eda2e70124e381b258495489c66a676557
lfs: provide more Batch API error info via a hint in the raised exception

A coworker had a typo in `lfs.url`, forgot it was even set because usually the
blob server is inferred, and then got a 404.  It would have been easier to debug
with the failing URL printed.

Patch

diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -263,16 +263,17 @@  class _gitlfsremote(object):
             'objects': objects,
             'operation': action,
         })
-        batchreq = util.urlreq.request('%s/objects/batch' % self.baseurl,
-                                       data=requestdata)
+        url = '%s/objects/batch' % self.baseurl
+        batchreq = util.urlreq.request(url, data=requestdata)
         batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
         batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
         try:
             rsp = self.urlopener.open(batchreq)
             rawjson = rsp.read()
         except util.urlerr.httperror as ex:
-            raise LfsRemoteError(_('LFS HTTP error: %s (action=%s)')
-                                 % (ex, action))
+            raise LfsRemoteError(_('LFS HTTP error: %s') % ex,
+                                 hint=_('api=%s, action=%s')
+                                 % (url, action))
         try:
             response = json.loads(rawjson)
         except ValueError:
diff --git a/tests/test-lfs-serve-access.t b/tests/test-lfs-serve-access.t
--- a/tests/test-lfs-serve-access.t
+++ b/tests/test-lfs-serve-access.t
@@ -29,7 +29,8 @@  Uploads fail...
   $ hg -R client push http://localhost:$HGPORT
   pushing to http://localhost:$HGPORT/
   searching for changes
-  abort: LFS HTTP error: HTTP Error 400: no such method: .git (action=upload)!
+  abort: LFS HTTP error: HTTP Error 400: no such method: .git!
+  (api=http://localhost:$HGPORT/.git/info/lfs/objects/batch, action=upload)
   [255]
 
 ... so do a local push to make the data available.  Remove the blob from the
@@ -50,7 +51,8 @@  Downloads fail...
   added 1 changesets with 1 changes to 1 files
   new changesets 525251863cad
   updating to branch default
-  abort: LFS HTTP error: HTTP Error 400: no such method: .git (action=download)!
+  abort: LFS HTTP error: HTTP Error 400: no such method: .git!
+  (api=http://localhost:$HGPORT/.git/info/lfs/objects/batch, action=download)
   [255]
 
   $ "$PYTHON" $RUNTESTDIR/killdaemons.py $DAEMON_PIDS