aws history show/list: UnboundLocalError instead of clear error when pager fails to start
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
Línea de trabajo
Comienza en awscli/utils.py, en OutputStreamFactory.get_pager_stream, y luego lee tests/unit/test_utils.py::TestOutputStreamFactory y su prueba existente de error del pager. Ejecuta las pruebas específicas y confirma que un fallo al iniciar un pager informa del error original en lugar de UnboundLocalError, mientras el caso de broken pipe sigue cubierto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
OutputStreamFactory.get_pager_stream (awscli/utils.py) is used by aws history show / aws history list to pipe output through a pager when running in a TTY. The try/except OSError/finally structure is meant to gracefully ignore OSErrors (e.g. broken pipe when the pager is closed abruptly):
@contextlib.contextmanager
def get_pager_stream(self, preferred_pager=None):
popen_kwargs = self._get_process_pager_kwargs(preferred_pager)
try:
process = self._popen(**popen_kwargs)
yield process.stdin
except OSError:
# Ignore IOError since this can commonly be raised when a pager
# is closed abruptly and causes a broken pipe.
pass
finally:
process.communicate()
The try block covers both process creation (self._popen(...)) and process usage (yield process.stdin). If self._popen(...) itself raises OSError — which happens whenever the configured pager binary doesn't exist (FileNotFoundError is an OSError subclass), e.g. AWS_PAGER/PAGER is misconfigured, or a minimal system has no less installed — then process is never assigned. The except OSError: pass swallows that exception, but the finally: process.communicate() then references the undefined local variable process, raising an unrelated UnboundLocalError instead of a clear error about the pager.
Repro
from awscli.utils import OutputStreamFactory
def bad_popen(*args, **kwargs):
raise OSError('no such file or directory: nonexistentpager')
factory = OutputStreamFactory(bad_popen)
with factory.get_pager_stream('nonexistentpager'):
pass
Output:
Traceback (most recent call last):
...
File "awscli/utils.py", line 253, in get_pager_stream
process.communicate()
UnboundLocalError: cannot access local variable 'process' where it is not associated with a value
Real-world trigger
Any user of aws history show/aws history list running in a TTY with AWS_PAGER/PAGER set to a nonexistent or misspelled command gets this confusing UnboundLocalError traceback instead of a clear "pager not found" style error.
Suggested fix
Only wrap the yield (process usage) in the try/except that's meant to swallow broken-pipe errors; let a failure to start the process propagate normally:
process = self._popen(**popen_kwargs)
try:
yield process.stdin
except OSError:
pass
finally:
process.communicate()
I have a PR ready with this fix plus a regression test in tests/unit/test_utils.py::TestOutputStreamFactory that reproduces the UnboundLocalError against the current code and passes with the fix.
Environment
aws-clidevelop branch (current)- Confirmed no existing test in
tests/unit/test_utils.py::TestOutputStreamFactoryexercisesself._popen(...)itself raisingOSError(existingtest_can_silence_io_error_from_pageronly coversprocess.stdinaccess raising afterPopensucceeds).
- Lenguaje dominante
- Python
- Estrellas
- 17.4k
- Forks
- 4.8k
- Merge medio
- 4 d 3 h
- PR fusionados (30 d)
- 64
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de aws/aws-cli
-
bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
feature-request login p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
aws/aws-cli#10739 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
-
CodeArtifact login: auth token leaked unredacted in CommandFailedError via subprocess stderrPosiblemente ocupada @PANYAMHEMANTH la tomó hace 7 días. Abiertocodeartifact login investigating p2
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 2 días
-
Refactor: drop redundant list() wrapper around sorted() in formatter.py/text.pyPosiblemente ocupada @Adityaj0 la tomó hace 88 días. Abiertofeature-request p3
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
aws/aws-cli#10568 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
aws configure set s3.* can raise UnboundLocalError when updating nested config blocksPosiblemente ocupada @fallintoplace la tomó hace 171 días. Abiertobug configure p3
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
aws/aws-cli#10348 · 1 comentario ·
Los mantenedores suelen responder en 2 días
Todos los issues de aws/aws-cli
Issues similares
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
gke-labs/kube-agents#5671 ·
Los mantenedores suelen responder en 1 día
-
docs(auth): Method B step 4 should tell users to tick "Use this client for an AI-powered agent"Abiertodocumentation next-release v0.9.6
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
khuisman/mcp-gee-sweet#1446 ·
Los mantenedores suelen responder en 1 día
-
In-box secret files written before their chmod: lc-creds, stacks tee, and the workspace tokenAbiertomodel:sonnet runtime:claude security size:S
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
FootprintAI/Containarium#3671 ·
Los mantenedores suelen responder en 1 día
-
HolidayBase: reassigning `language` does not re-initialize translations or re-populate holidaysPosiblemente ocupada @shikhabhadoria la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vacanza/holidays#4116 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug CLI exec
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día