graceful handling of common issues - check ppa format before engaging LP

Bug #1989084 reported by Christian Ehrhardt 
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ppa-dev-tools
Fix Released
Undecided
Bryce Harrington

Bug Description

This works:

$ ppa wait ppa:paelzer/lp-1975764-dpdk-mre-sept-2022

But many other close syntaxes that are just wrong could be typed accidentially, for example:

$ ppa wait ppa/paelzer/lp-1975764-dpdk-mre-sept-2022
Traceback (most recent call last):
  File "/usr/local/bin/ppa", line 4, in <module>
    __import__('pkg_resources').run_script('ppa-dev-tools==0.1.0', 'ppa')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1453, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 533, in <module>
    sys.exit(main(args))
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 522, in main
    return func(lp, config)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 434, in command_wait
    ppa = get_ppa(lp, config)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 203, in get_ppa
    return Ppa(
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa.py", line 70, in __init__
    assert team_name
AssertionError

[✗=1]─[paelzer@Keschdeichel ~/work/dpdk/deb_dpdk]──[289970]──[10:43 Do Sep 08]──(lp-1975764-MRE-Sept-2022-KINETIC)
$ ppa wait ppa:paelzer/lp-1975764-dpdk-mre-sept-2022/kinetic
Traceback (most recent call last):
  File "/usr/local/bin/ppa", line 4, in <module>
    __import__('pkg_resources').run_script('ppa-dev-tools==0.1.0', 'ppa')
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 656, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1453, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 533, in <module>
    sys.exit(main(args))
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 522, in main
    return func(lp, config)
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/EGG-INFO/scripts/ppa", line 437, in command_wait
    if not ppa.has_packages():
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa.py", line 222, in has_packages
    return list(self.archive.getPublishedSources()) != []
  File "/usr/local/lib/python3.10/dist-packages/ppa_dev_tools-0.1.0-py3.10.egg/ppa/ppa.py", line 96, in archive
    return owner.getPPAByName(name=self.ppa_name)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 592, in __call__
    response, content = self.root._browser._request(
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 429, in _request
    raise error
lazr.restfulclient.errors.BadRequest: HTTP Error 400: Bad Request
Response headers:
---
-content-encoding: gzip
connection: close
content-length: 279
content-security-policy: frame-ancestors 'self';
content-type: text/plain;charset=utf-8
date: Thu, 08 Sep 2022 08:43:56 GMT
server: gunicorn/19.8.1
status: 400
strict-transport-security: max-age=15552000
vary: Accept,Accept-Encoding
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-launchpad-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-lazr-notifications: []
x-powered-by: Zope (www.zope.org), Python (www.python.org)
x-request-id: 7814bcca-7f04-4e17-9dd1-e7f74cc8a581
x-vcs-revision: b6507fd2ad40d5507636508b2c5a315f269f7007
x-xss-protection: 1; mode=block
---
Response body:
---
b"name: \nInvalid name 'lp-1975764-dpdk-mre-sept-2022/kinetic'. Names must be at least two characters long\nand start with a letter or number. All letters must be lower-case.\nThe characters <samp>+</samp>, <samp>-</samp> and <samp>.</samp>\nare also allowed after the first character."
---

AFAICS there is a clear syntax we have to follow, should we consider throwing a regex on it before bothering LP, and gracefully tell the user "your argument seems to be wrong and does not match <format>"?
That seems more friendly and comfortable to me.

Related branches

Revision history for this message
Bryce Harrington (bryce) wrote :

The regex pre-check is not a bad idea.

At a minimum from this and other bugs it looks clear that this code needs wrapped in a try block, and the error extracted (and de-html'd) from the exception's response for the user.

Bryce Harrington (bryce)
Changed in ppa-dev-tools:
assignee: nobody → Bryce Harrington (bryce)
status: New → In Progress
Revision history for this message
Bryce Harrington (bryce) wrote :

commit 639f536b31052f05769fb7dc271311b203133afd
Author: Bryce Harrington <email address hidden>
AuthorDate: Tue Sep 13 00:59:02 2022 -0700
Commit: Bryce Harrington <email address hidden>
CommitDate: Tue Sep 13 00:59:02 2022 -0700

    ppa: Improve handling of invalid ppa formats

    Instead of dumping a backtrace when incorrect ppa ID's are given, print
    out a distinct error message and then print usage information.

    Fixes: https://bugs.launchpad.net/ppa-dev-tools/+bug/1989084

Changed in ppa-dev-tools:
status: In Progress → Fix Committed
Bryce Harrington (bryce)
Changed in ppa-dev-tools:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.