StorePushError doesn't grok the new store error responses

Bug #1705684 reported by Daniel Manrique on 2017-07-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
Medium
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/__init__.py b/snapcraft/storeapi/__init__.py
index 8d8e208..853e0ad 100644
--- a/snapcraft/storeapi/__init__.py
+++ b/snapcraft/storeapi/__init__.py
@@ -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/store.py", line 123, in push
    snapcraft.push(snap_file, channel_list)
  File "/usr/lib/python3/dist-packages/snapcraft/_store.py", line 424, in push
    store.push_precheck(snap_name)
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/__init__.py", line 204, in push_precheck
    self.sca.snap_push_precheck, snap_name)
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/__init__.py", line 183, in _refresh_if_necessary
    return func(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/storeapi/__init__.py", 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>
    obj=dict(project=snapcraft.ProjectOptions()))
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/store.py", line 125, in push
    echo.error(e)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/echo.py", line 42, in error
    click.echo('\033[0;31m{}\033[0m'.format(msg))
  File "/usr/lib/python3/dist-packages/snapcraft/internal/errors.py", 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