Invalid yaml in a charm's actions.yaml results in cryptic "unexpected error"

Bug #1947752 reported by Daniel Manrique
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snap Store Server
Fix Committed
Undecided
Tong-Wook Shinn

Bug Description

This is a charm whose actions.yaml doesn't parse correctly (it's invalid yaml).

The user sees:

2021-10-19 09:05:01.028 Status checked: {'revisions': [{'errors': [{'code': 'review-error', 'message': 'Unexpected error'}], 'revision': None, 'status': 'rejected', 'upload-id': '2d5d38aa-13e4-4bfb-bfee-2455ba5bdb99'}]}

On our side, the exception from packagereview is:

Failed to scan /srv/packagereview-worker/worker-tmp/tmpzsz79z47/2d5d38aa-13e4-4bfb-bfee-2455ba5bdb99
Expected '<document start>', but found '<block sequence start>'
  in "actions.yaml", line 2, column 1

The above is a yaml exception, the thing here is that the charm_scan method has a large block where it tries a few things and catches a few exceptions, but the loading of yaml files (done in line 143):

            extra = extract_optional_files(charm, optional)

is not wrapped in any of the specific exceptions, so any exception in that block falls through to:

    except Exception as exc:
        logger.exception("Failed to scan %s", download_path)
        output = dict(error=str(exc), reason="Unexpected error")
        return ScanStatus.rejected.value, output

It would be good to wrap extract_optional_files in a try: block and raise a more explicit, clearer error that a specific file has yaml parsing issues.

Daniel Manrique (roadmr)
tags: added: bite-size charmhub
Tong-Wook Shinn (tshinn)
Changed in snapstore-server:
assignee: nobody → Tong-Wook Shinn (tshinn)
Tong-Wook Shinn (tshinn)
Changed in snapstore-server:
status: New → In Progress
Tong-Wook Shinn (tshinn)
Changed in snapstore-server:
status: In Progress → Fix Committed
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.