Suppress the traceback unless --debug is given

Bug #1621445 reported by Simon Fels on 2016-09-08
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Image
High
Barry Warsaw

Bug Description

Providing a model assertion which does have a line break between content and signature causes a uncought exception:

simon@nirvana ~/Work/ubuntu/snappy/hwe/images $ sudo /snap/bin/ubuntu-image -c edge -o test.img pc.model
error: cannot decode model assertion "pc.model": assertion content/signature separator not found
COMMAND FAILED: snap prepare-image --channel=edge pc.model /tmp/tmp4x95i_f2/unpackuncaught exception in state machine step: [1] prepare_image
Traceback (most recent call last):
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/state.py", line 68, in __next__
    step()
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/builder.py", line 141, in prepare_image
    snap(self.args.model_assertion, self.unpackdir, self.args.channel, self.args.extra_snaps)
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/helpers.py", line 124, in snap
    run(cmd, stdout=None, stderr=None)
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/helpers.py", line 106, in run
    sys.stderr.write(proc.stdout)
TypeError: write() argument must be str, not None
Crash in state machine
Traceback (most recent call last):
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/__main__.py", line 118, in main
    list(state_machine)
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/state.py", line 68, in __next__
    step()
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/builder.py", line 141, in prepare_image
    snap(self.args.model_assertion, self.unpackdir, self.args.channel, self.args.extra_snaps)
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/helpers.py", line 124, in snap
    run(cmd, stdout=None, stderr=None)
  File "/snap/ubuntu-image/13/usr/lib/python3.5/site-packages/ubuntu_image/helpers.py", line 106, in run
    sys.stderr.write(proc.stdout)
TypeError: write() argument must be str, not None

simon@nirvana ~/Work/ubuntu/snappy/hwe/images $ cat pc.model
type: model
authority-id: canonical
series: 16
brand-id: canonical
model: pc
architecture: amd64
gadget: pc
kernel: pc-kernel
timestamp: 2016-08-31T00:00:00.0Z
sign-key-sha3-384: 9tydnLa6MTJ-jaQTFUXEwHl1yRx7ZS4K5cyFDhYDcPzhS7uyEkDxdUjg9g08BtNn
AcLBXAQAAQoABgUCV8lRDQAKCRDgT5vottzAEg9GEACsSb+qXB34mwESsd7ns6VpM9BfAOOSstwB
KJlWOlcJ39M7is/fO+dxRH4XsI7Td6BI1WEf5188sJuld8APUsTPn8tPYN3JB5CJ8Edkr6p78YUW
f3Wo26USAE32ewjq9kHo6uBqIr4VixjTXfGUeDXc7tvKcduIMokSKjDLRHJRur1NC8LjkBn2ZPi8
9d0BpJzr5y8wK0yFEyAhaS8H8LvL7VMjKG7/BkZcQ0a3jv69qh9jdmxnKDN2zcd1btRR1Giew3gw
VJ8lNtfxQSWi+nYNEuzDqwKdffo9sVyCzBC+vEH3xYYk8NpRx2QgCSzDCPMoxaJgLwhAeWz6mHQp
8EaGOsMZm7c85BXUcdJGEhZ5MpNGSzCb/ifgOKBB6zYzekiQh4TVLgi9Uk/acsLH75vNrI8Kwyl+
r4Pahf///LbeWNwcEonaSV48S5fg3QqxEQeb42xcp6wPfRr7LN1LvQ9kRQTt42GDAlIva5HKlo0T
cUb5A4zz3IlBn/KQ4BS/2sBcixrH97tHInef4oA8IrBiBDGnIv/s4qyZ+gB5fX8Ohnn/a5bUgU5u
GmwRQ12Ix54YGJrzZocu1AiQINij4s6ZSoJAEJobI9VBK8WnV8PRmra6UJonV+qrJOiSKTJVCkAF
+RFartQL+pjF/H29FsyBkIEcPwhTslxWKUWajHsExw==

After adding the missing line break everything works as expected.

ubuntu-image version:

simon@nirvana ~/Work/ubuntu/snappy/hwe/images $ snap list ubuntu-image
Name Version Rev Developer Notes
ubuntu-image 0.5+mvo6 13 canonical devmode

Expectation: ubuntu-image should just show a error message and not report a uncought exception.

Steve Langasek (vorlon) wrote :

Specific instance of the more general problem of bug #1617421

Changed in ubuntu-image:
assignee: nobody → Barry Warsaw (barry)
importance: Undecided → High
status: New → Triaged
summary: - Uncought exception for invalid model assertion file
+ Uncaught exception for invalid model assertion file
Barry Warsaw (barry) on 2016-11-01
Changed in ubuntu-image:
milestone: none → 0.11
Barry Warsaw (barry) on 2016-11-02
Changed in ubuntu-image:
status: Triaged → In Progress

I think what we'll do is use the logging machinery here. At default log level, we'll print that `snap prepare-image` failed. Turn on debug logging and you'll see the whole traceback.

Barry Warsaw (barry) on 2016-11-03
summary: - Uncaught exception for invalid model assertion file
+ Suppress the traceback unless --debug is given
Barry Warsaw (barry) on 2016-11-03
Changed in ubuntu-image:
status: In Progress → Fix Committed
Barry Warsaw (barry) on 2016-11-04
Changed in ubuntu-image:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers