Skip to content

Avoid KeyError when a bls directory is empty - #67

Open
pefoley2 wants to merge 1 commit into
gentoo:masterfrom
pefoley2:master
Open

pefoley2 wants to merge 1 commit into
gentoo:masterfrom
pefoley2:master

Conversation

@pefoley2

@pefoley2 pefoley2 commented May 9, 2026

Copy link
Copy Markdown

If a bls directory is empty, eclean-kernel fails with a KeyError. This can happen when too many kernels build up and the /boot partition is filled to the point that writing the initramfs fails.

Fixes #60

e.g.
File "/home/peter/eclean-kernel/.venv/bin/eclean-kernel", line 10, in 12:42 [54/433]
sys.exit(setuptools_main())
~~~~~~~~~~~~~~~^^
File "/home/peter/eclean-kernel/ecleankernel/main.py", line 391, in setuptools_main
sys.exit(main(sys.argv[1:]))
~~~~^^^^^^^^^^^^^^
File "/home/peter/eclean-kernel/ecleankernel/main.py", line 236, in main
kernels = layout.find_kernels(exclusions=exclusions)
File "/home/peter/eclean-kernel/ecleankernel/layout/blspec.py", line 130, in find_kernels
kernels[(ver, "bls")].all_files.append(
~~~~~~~^^^^^^^^^^^^^^
KeyError: ('7.0.1-gentoo-dist', 'bls')

@pefoley2

Copy link
Copy Markdown
Author

@mgorny Friendly ping? I'm still seeing this on my system.

@mgorny

mgorny commented Sep 20, 2026

Copy link
Copy Markdown
Member

Sorry, missed it.

That said, I wonder if a more reasonable thing to do wouldn't be to record this as a stray directory, and therefore have ek remove it.

@pefoley2

Copy link
Copy Markdown
Author

Good point, reworked to do so.

Comment thread ecleankernel/layout/blspec.py Outdated
Comment on lines +130 to +131
else:
kernels[(ver, "bls")] = k

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks but the else branch makes little sense here, given the loop never breaks, so it will always be executed.

Sorry for bothering you with major refactor, but I'm thinking of:

  • assigning the new Kernel() straight to kernels[...]
  • passing that to append_kernel_files() and ignoring the return value

If you don't want to do that, let me know and I'll take over.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this look?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I meant removing the k helper variable, not adding more of it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, like this?

If a bls directory is empty, eclean-kernel fails with a KeyError.
This can happen when too many kernels build up and the /boot partition
is filled to the point that writing the initramfs fails.

Fixes gentoo#60

e.g.
  File "/home/peter/eclean-kernel/.venv/bin/eclean-kernel", line 10, in <module>                                                                                                                    12:42 [54/433]
    sys.exit(setuptools_main())
             ~~~~~~~~~~~~~~~^^
  File "/home/peter/eclean-kernel/ecleankernel/__main__.py", line 391, in setuptools_main
    sys.exit(main(sys.argv[1:]))
             ~~~~^^^^^^^^^^^^^^
  File "/home/peter/eclean-kernel/ecleankernel/__main__.py", line 236, in main
    kernels = layout.find_kernels(exclusions=exclusions)
  File "/home/peter/eclean-kernel/ecleankernel/layout/blspec.py", line 130, in find_kernels
    kernels[(ver, "bls")].all_files.append(
    ~~~~~~~^^^^^^^^^^^^^^
KeyError: ('7.0.1-gentoo-dist', 'bls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There's an keyError with 6.13.1-gentoo-dist and bls

2 participants