Skip to content

keyboard: Don't crash if setxkbmap query fails or returns unexpected output#179

Open
ashishkr96 wants to merge 1 commit intolinuxmint:masterfrom
ashishkr96:fix-setxkbmap-query-parsing
Open

keyboard: Don't crash if setxkbmap query fails or returns unexpected output#179
ashishkr96 wants to merge 1 commit intolinuxmint:masterfrom
ashishkr96:fix-setxkbmap-query-parsing

Conversation

@ashishkr96
Copy link
Copy Markdown

Summary

Fixes #176ValueError: too many values to unpack (expected 2) from build_kb_lists() when launching the installer on a live LMDE 7 session.

Root cause

usr/lib/live-installer/main.py:752 parsed the live session's setxkbmap -query output by piping through awk and tuple-unpacking the result of .split() into exactly two names. .split() collapses all whitespace including newlines, so the unpack only succeeds when there are precisely two whitespace-separated tokens in the entire output. Anything else raises ValueError and aborts the installer before the keyboard page can render.

The most likely real-world trigger — and the one consistent with the traceback in #176 — is setxkbmap failing (binary missing on the live image, or an environment where the X-protocol query can't run). When that happens, subprocess.getoutput returns shell error text like sh: 1: setxkbmap: not found — five tokens, instant crash.

Fix

Parse setxkbmap -query line-by-line, picking off model: and layout: if present. If the query fails or the lines aren't there, leave the locals at None. The downstream pre-selection logic at main.py:794-802 already wraps the lookups in except NameError, so an unset/None value just means "no pre-selection" — the user picks from the list manually, which is far better than a hard crash.

Behavior on the happy path is unchanged: normal setxkbmap -query output produces the same (model, layout) pair as before, including the comma-separated form for multi-layout setups.

Test plan

  • Python syntax check on the patched file (python3 -m py_compile).
  • Unit-tested the new parser against: normal output, multi-layout (us,de), missing setxkbmap (shell error), empty output, partial output (only model: / only layout:), and lines with junk preceding the real ones. Happy path identical to old behavior; all failure modes return (None, None) or (None, value) instead of crashing.
  • End-to-end run on a live LMDE 7 ISO on the affected hardware (Dell OptiPlex 755 from Can not install LMDE 7 from usb #176) — left for reviewers with that environment, since the original report could not reach the installer at all without this fix.

…output

build_kb_lists() ran the live session's `setxkbmap -query` output through
`awk` and then `.split()`-unpacked the result into exactly two names. Any
deviation from "exactly 2 whitespace-separated tokens" raised
ValueError: too many values to unpack (expected 2) and aborted the
installer before it could draw the keyboard page.

The most likely real-world trigger on a live ISO is `setxkbmap` failing
(missing binary, or an environment where the X-protocol query can't run),
in which case `subprocess.getoutput` returns the shell error text
(`sh: 1: setxkbmap: not found`) -- five tokens, instant crash.

Parse line-by-line instead, and fall back to leaving the locals at None
when the query is unhelpful. The existing `except NameError` blocks at
the pre-selection sites already handle "couldn't determine current
model/layout" gracefully -- the user just picks from the list.

Closes linuxmint#176.
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.

Can not install LMDE 7 from usb

1 participant