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

    plugin: nil
      - 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/", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 782, in main
    rv = self.invoke(ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 1236, in invoke
    return Command.invoke(self, ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 610, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/", line 132, in run
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/", line 89, in invoke
    return super().invoke(ctx)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/click/", line 610, in invoke
    return callback(*args, **kwargs)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/cli/", 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/", line 103, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/", line 137, in execute, part_names)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/", 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/", line 205, in _handle_step
    getattr(self, "_run_{}".format(
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/", 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/", line 322, in _run_step
    self._prepare_step(step=step, part=part)
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/lifecycle/", line 313, in _prepare_step
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/", line 475, in prepare_pull
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/pluginhandler/", line 460, in _fetch_stage_packages
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/repo/", line 462, in fetch_stage_packages
  File "/snap/snapcraft/6466/lib/python3.6/site-packages/snapcraft/internal/repo/", 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'

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

Operation in progress: ua attach

Enable services with: ua enable <service>

           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 xenial-security InRelease [109 kB]                                                                   
Get:2 xenial InRelease [247 kB]                                                                             
Get:3 xenial-security/main amd64 Packages [1648 kB]                                                        
Get:4 xenial-infra-security InRelease [7497 B]                                                           
Get:5 xenial-security/main Translation-en [380 kB]                                                         
Get:6 xenial-security/restricted amd64 Packages [9824 B]                                                   
Get:7 xenial-security/restricted Translation-en [2152 B]                                                   
Get:8 xenial-security/universe amd64 Packages [785 kB]                                                     
Get:9 xenial-security/universe Translation-en [225 kB]                                                     
Get:10 xenial-security/multiverse amd64 Packages [7864 B]                                                  
Get:11 xenial-infra-updates InRelease [7475 B]                                                           
Get:12 xenial-security/multiverse Translation-en [2672 B]                                                  
Get:13 xenial-updates InRelease [109 kB]                                                                    
Get:14 xenial-infra-security/main amd64 Packages [59.1 kB]                                               
Get:15 xenial-backports InRelease [107 kB]                                                                  
Get:16 xenial/main amd64 Packages [1201 kB]                                                                 
Get:17 xenial-infra-updates/main amd64 Packages [4746 B]                                                 
Get:18 xenial/main Translation-en [568 kB]                                                                  
Get:19 xenial/restricted amd64 Packages [8344 B]                                                            
Get:20 xenial/restricted Translation-en [2908 B]                                                            
Get:21 xenial/universe amd64 Packages [7532 kB]                                                             
Get:22 xenial/universe Translation-en [4354 kB]                                                             
Get:23 xenial/multiverse amd64 Packages [144 kB]                                                            
Get:24 xenial/multiverse Translation-en [106 kB]                                                            
Get:25 xenial-updates/main amd64 Packages [2049 kB]                                                         
Get:26 xenial-updates/main Translation-en [482 kB]                                                          
Get:27 xenial-updates/restricted amd64 Packages [10.2 kB]                                                   
Get:28 xenial-updates/restricted Translation-en [2272 B]                                                    
Get:29 xenial-updates/universe amd64 Packages [1219 kB]                                                     
Get:30 xenial-updates/universe Translation-en [358 kB]                                                      
Get:31 xenial-updates/multiverse amd64 Packages [22.6 kB]                                                   
Get:32 xenial-updates/multiverse Translation-en [8476 B]                                                    
Get:33 xenial-backports/main amd64 Packages [9812 B]                                                        
Get:34 xenial-backports/main Translation-en [4456 B]                                                        
Get:35 xenial-backports/universe amd64 Packages [11.3 kB]                                                   
Get:36 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 xenial-infra-security main
# deb-src xenial-infra-security main

deb xenial-infra-updates main
# deb-src 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


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.