Snapcraft crash when ESM repositories are present

This could be something of a corner case situation, but I’ve been hitting snapcraft crashes recently so wanted to make people aware. The error message reported is:

'NoneType' object has no attribute 'priority'

To end up in this situation I think you currently must be using --destructive-mode such that the system you are building on has received the ubuntu-advantage-tools package and had the ESM repositories added to the sources list. Disabling those repos again allows the snap to be built.

A simple snapcraft.yaml to cause the crash:

name: my-snap-name
base: core
version: '0.1'
summary: Test stage-package
description: Test

grade: devel
confinement: devmode

parts:
  my-part:
    plugin: nil
    stage-packages:
      - tree

Here is the trace:

Traceback (most recent call last):
  File "/snap/snapcraft/6466/bin/snapcraft", line 33, in <module>
    sys.exit(load_entry_point('snapcraft==4.7.1', 'console_scripts', 'snapcraft')())
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 1236, in invoke
    return Command.invoke(self, ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/_runner.py", line 132, in run
    snap_command.invoke(ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/_command.py", line 89, in invoke
    return super().invoke(ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/lifecycle.py", line 388, in snap
    _execute(steps.PRIME, parts=tuple(), pack_project=True, output=output, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/lifecycle.py", line 103, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 137, in execute
    executor.run(step, part_names)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 191, in run
    self._handle_step(part_names, part, step, current_step, cli_config)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 205, in _handle_step
    getattr(self, "_run_{}".format(current_step.name))(part)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 247, in _run_pull
    self._run_step(step=steps.PULL, part=part, progress="Pulling")
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 322, in _run_step
    self._prepare_step(step=step, part=part)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/_runner.py", line 313, in _prepare_step
    preparation_function()
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 475, in prepare_pull
    self._fetch_stage_packages()
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/__init__.py", line 460, in _fetch_stage_packages
    target_arch=self._project._get_stage_packages_target_arch(),
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/repo/_deb.py", line 462, in fetch_stage_packages
    apt_cache.unmark_packages(filtered_names)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/repo/apt_cache.py", line 256, in unmark_packages
    if package.candidate.priority == "essential":
AttributeError: 'NoneType' object has no attribute 'priority'

Is there a bug for this? Is this using destructive mode?

I was unable to reproduce in a clean environment:

root@u16:~# ua attach <token>
Enabling default service esm-infra
Updating package lists
UA Infra: ESM enabled
A reboot is required to complete install.
This machine is now attached to 'Ubuntu Advantage - Standard'

SERVICE       ENTITLED  STATUS    DESCRIPTION
esm-infra     yes       enabled   UA Infra: Extended Security Maintenance (ESM)
fips          no        —         NIST-certified FIPS modules
fips-updates  no        —         Uncertified security updates to FIPS modules
livepatch     yes       n/a       Canonical Livepatch service

NOTICES
Operation in progress: ua attach

Enable services with: ua enable <service>

                Account: 
           Subscription: Ubuntu Advantage - Standard
            Valid until: 3999-12-31 00:00:00
Technical support level: standard

root@u16:~/testx# sudo snap install snapcraft --edge --classic
snapcraft (edge) 4.7.1.post26+gita9b60efe from Canonical✓ installed

root@u16:~/testx# snapcraft --destructive-mode
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]                                                                   
Get:2 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]                                                                             
Get:3 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [1648 kB]                                                        
Get:4 https://esm.ubuntu.com/infra/ubuntu xenial-infra-security InRelease [7497 B]                                                           
Get:5 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [380 kB]                                                         
Get:6 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [9824 B]                                                   
Get:7 http://security.ubuntu.com/ubuntu xenial-security/restricted Translation-en [2152 B]                                                   
Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [785 kB]                                                     
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [225 kB]                                                     
Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [7864 B]                                                  
Get:11 https://esm.ubuntu.com/infra/ubuntu xenial-infra-updates InRelease [7475 B]                                                           
Get:12 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [2672 B]                                                  
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]                                                                    
Get:14 https://esm.ubuntu.com/infra/ubuntu xenial-infra-security/main amd64 Packages [59.1 kB]                                               
Get:15 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]                                                                  
Get:16 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1201 kB]                                                                 
Get:17 https://esm.ubuntu.com/infra/ubuntu xenial-infra-updates/main amd64 Packages [4746 B]                                                 
Get:18 http://archive.ubuntu.com/ubuntu xenial/main Translation-en [568 kB]                                                                  
Get:19 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [8344 B]                                                            
Get:20 http://archive.ubuntu.com/ubuntu xenial/restricted Translation-en [2908 B]                                                            
Get:21 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7532 kB]                                                             
Get:22 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en [4354 kB]                                                             
Get:23 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]                                                            
Get:24 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB]                                                            
Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [2049 kB]                                                         
Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [482 kB]                                                          
Get:27 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [10.2 kB]                                                   
Get:28 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Translation-en [2272 B]                                                    
Get:29 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [1219 kB]                                                     
Get:30 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [358 kB]                                                      
Get:31 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [22.6 kB]                                                   
Get:32 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8476 B]                                                    
Get:33 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [9812 B]                                                        
Get:34 http://archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [4456 B]                                                        
Get:35 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [11.3 kB]                                                   
Get:36 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [4476 B]                                                    
Fetched 21.8 MB in 0s (0 B/s)                                                                                                                
Get:1 tree_1.7.0-3_amd64.deb [40.6 kB]                                                                                                       
Fetched 40.6 kB in 0s (0 B/s)                                                                                                                
Pulling my-part 
+ snapcraftctl pull
Building my-part 
+ snapcraftctl build
Staging my-part 
+ snapcraftctl stage
Priming my-part 
+ snapcraftctl prime
Snapping |                                                                                                                         
Snapped my-snap-name_0.1_amd64.snap

There is a work ticket in to address the crash, but for some reason Snapcraft was unable to find a candidate package for tree. Do you have any unusual, manual customization of apt config?

tree is in universe perhaps you don’t have the universe repository enabled.

No idea why tree was the package that came to mind to use as the test snap, could have picked something else!

The only other thing that I can see in my container that pertains to apt is running a dist-upgrade. I don’t have any other PPAs or anything added

The fix is simple, but I am interested in why Chris cannot reproduce. Do you have esm-apps enabled?

I haven’t done a ua attach or anything like that.

I can cause/stop the crash by commenting the deb sources in /etc/apt/sources.list.d/ubuntu-esm-infra.list:

# Written by ubuntu-advantage-tools
deb https://esm.ubuntu.com/infra/ubuntu xenial-infra-security main
# deb-src https://esm.ubuntu.com/infra/ubuntu xenial-infra-security main

deb https://esm.ubuntu.com/infra/ubuntu xenial-infra-updates main
# deb-src https://esm.ubuntu.com/infra/ubuntu xenial-infra-updates main

Sorry, I don’t know what esm-apps is.

Ah, that’s the key. No UA attach, I’ve reproduced. Working on a fix…

1 Like

Fix available for testing:
sudo snap refresh snapcraft --channel edge/pr-3528

PR: https://github.com/snapcore/snapcraft/pull/3528

Sorry, got distracted by other things and didnt reply. This branch is working nicely for me, thanks so much!

1 Like

This is part of Snapcraft 4.8 currently in a Call for testing and due tomorrow in case you want to give it a spin and comment on Call for testing: Snapcraft 4.8.