StorePushError doesn't grok the new store error responses

Bug #1705684 reported by Daniel Manrique on 2017-07-21
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sergio Schvezov

Bug Description

When trying to push a snap to the wrong store an error response was generated, but snapcraft crashed without showing an appropriate error message built from the response. This seems to be because the StorePushError exception is trying to get the 'text' from the response's json but there isn't one. How to reproduce:

Apply this change to snapcraft to send a store header:

diff --git a/snapcraft/storeapi/ b/snapcraft/storeapi/
index 8d8e208..853e0ad 100644
--- a/snapcraft/storeapi/
+++ b/snapcraft/storeapi/
@@ -582,6 +582,7 @@ class SCAClient(Client):
             'snap-push/', data=json.dumps(data),
             headers={'Authorization': auth,
                      'Content-Type': 'application/json',
+ 'X-Ubuntu-Store': 'whatever',
                      'Accept': 'application/json'})
         if not response.ok:
             raise errors.StorePushError(data['name'], response)

- Try to push a snap

This is what I get:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/snapcraft/cli/", line 123, in push
    snapcraft.push(snap_file, channel_list)
  File "/usr/lib/python3/dist-packages/snapcraft/", line 424, in push
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/", line 204, in push_precheck, snap_name)
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/", line 183, in _refresh_if_necessary
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/", line 572, in snap_push_precheck
    raise errors.StorePushError(data['name'], response)
snapcraft.storeapi.errors.StorePushError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 32, in <module>
  File "/usr/lib/python3/dist-packages/click/", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/", line 125, in push
  File "/usr/lib/python3/dist-packages/snapcraft/cli/", line 42, in error
  File "/usr/lib/python3/dist-packages/snapcraft/internal/", line 42, in __str__
    return self.fmt.format([], **self.__dict__)
KeyError: 'text'

The response contains this (note: no text).

b'{"error_list": [{"message": "Invalid store.", "code": "invalid-field", "extra": {"field": "X-Ubuntu-Store", "value": "planeo"}}]}'

Sergio Schvezov (sergiusens) wrote :

Did the API change

Changed in snapcraft:
status: New → Triaged
Sergio Schvezov (sergiusens) wrote :

Said differently, where is this documented?

Changed in snapcraft:
importance: Undecided → Medium
assignee: nobody → Sergio Schvezov (sergiusens)
milestone: none → 2.35
Changed in snapcraft:
milestone: 2.35 → none
Sergio Schvezov (sergiusens) wrote :
Changed in snapcraft:
status: Triaged → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers