keyboard: Don't crash if setxkbmap query fails or returns unexpected output#179
Open
ashishkr96 wants to merge 1 commit intolinuxmint:masterfrom
Open
keyboard: Don't crash if setxkbmap query fails or returns unexpected output#179ashishkr96 wants to merge 1 commit intolinuxmint:masterfrom
ashishkr96 wants to merge 1 commit intolinuxmint:masterfrom
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #176 —
ValueError: too many values to unpack (expected 2)frombuild_kb_lists()when launching the installer on a live LMDE 7 session.Root cause
usr/lib/live-installer/main.py:752parsed the live session'ssetxkbmap -queryoutput by piping throughawkand 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 raisesValueErrorand 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
setxkbmapfailing (binary missing on the live image, or an environment where the X-protocol query can't run). When that happens,subprocess.getoutputreturns shell error text likesh: 1: setxkbmap: not found— five tokens, instant crash.Fix
Parse
setxkbmap -queryline-by-line, picking offmodel:andlayout:if present. If the query fails or the lines aren't there, leave the locals atNone. The downstream pre-selection logic atmain.py:794-802already wraps the lookups inexcept NameError, so an unset/Nonevalue 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 -queryoutput produces the same(model, layout)pair as before, including the comma-separated form for multi-layout setups.Test plan
python3 -m py_compile).us,de), missingsetxkbmap(shell error), empty output, partial output (onlymodel:/ onlylayout:), 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.