snapcraft icon indicating copy to clipboard operation
snapcraft copied to clipboard

Poor error reporting for bases earlier than 24

Open dilyn-corner opened this issue 5 months ago • 2 comments

Bug Description

If something horrifically unexpected happens in a YAML snapcraft will throw a traceback instead of reporting a proper error.

Specifically, snapcraft will usefully tell me that I have some bad snapcraft.yaml content and what was expected when building base: core24 snaps. However, a traceback is thrown instead of I use base: core22 snaps.

To Reproduce

Install snapcraft 8.x (using 8.10.y myself) and:

mkdir t && cd t; snapcraft init
echo 'build-packages:' >> snap/snapcraft.yaml
snapcraft
sed -i 's/core24/core22/' snap/snapcraft.yaml
snapcraft

Environment

Ubuntu 25.04, snapcraft 8.x, building with LXD.

snapcraft.yaml

name: test # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: nil

build-packages:

Relevant log output

dilyn@Ares:~/test -> sc
Starting snapcraft, version 8.10.0.post45
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20250714-150700.168675.log'
Bad snapcraft.yaml content:
- input should be a valid list (in field 'parts.snapcraft/core.build-packages')
dilyn@Ares:~/test -> hx snap/snapcraft.yaml                                                                                 
dilyn@Ares:~/test -> sc                      
Starting snapcraft, version 8.10.0.post45
Logging execution to '/home/dilyn/.local/state/snapcraft/log/snapcraft-20250714-150707.652601.log'
Running on amd64 for amd64Traceback (most recent call last):
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/application.py", line 467, in main
    return app.run()
           ^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/craft_application/application.py", line 615, in run
    return_code = self._run_inner()
                  ^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/application.py", line 178, in _run_inner
    return_code = super()._run_inner()
                  ^^^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/craft_application/application.py", line 561, in _run_inner
    dispatcher = self._get_dispatcher()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/application.py", line 405, in _get_dispatcher
    self._check_for_classic_fallback()
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/application.py", line 317, in _check_for_classic_fallback
    raise errors.ClassicFallback()
snapcraft.errors.ClassicFallback

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/snap/snapcraft/x19/bin/snapcraft", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/application.py", line 470, in main
    return cli.run()
           ^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/cli.py", line 256, in run
    _run_dispatcher(dispatcher, global_args)
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/cli.py", line 229, in _run_dispatcher
    dispatcher.run()
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/craft_cli/dispatcher.py", line 528, in run
    return self._loaded_command.run(self._parsed_command_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/commands/core22/lifecycle.py", line 272, in run
    super().run(parsed_args)
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/commands/core22/lifecycle.py", line 145, in run
    parts_lifecycle.run(self.name, parsed_args)
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/parts/lifecycle.py", line 95, in run
    yaml_data_for_arch = yaml_utils.apply_yaml(yaml_data, build_on, build_for)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/parts/yaml_utils.py", line 203, in apply_yaml
    yaml_data["parts"] = grammar.process_parts(
                         ^^^^^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/parts/grammar.py", line 77, in process_parts
    process_part(part_yaml_data=part, processor=processor)
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/snapcraft/parts/grammar.py", line 47, in process_part
    processed_grammar: list[Any] | None = processor.process(
                                          ^^^^^^^^^^^^^^^^^^
  File "/snap/snapcraft/x19/lib/python3.12/site-packages/craft_grammar/_processor.py", line 89, in process
    for section in grammar:
TypeError: 'NoneType' object is not iterable

Additional context

No response

dilyn-corner avatar Jul 14 '25 19:07 dilyn-corner

Nice find, this is not a good user experience.

Snapcraft should be more robust when processing grammar, in order to present a good error message.

mr-cal avatar Jul 21 '25 13:07 mr-cal

Thank you for reporting your feedback to us!

The internal ticket has been created: https://warthogs.atlassian.net/browse/SNAPCRAFT-1186.

This message was autogenerated