Skip to content

Handle KeyError in plain output#309

Open
atomicules wants to merge 1 commit into
mbovo:mainfrom
atomicules:key-error-in-plain
Open

Handle KeyError in plain output#309
atomicules wants to merge 1 commit into
mbovo:mainfrom
atomicules:key-error-in-plain

Conversation

@atomicules

Copy link
Copy Markdown

For whatever reason I get this error:

File "/home/simon/.local/lib/python3.11/site-packages/pdh/main.py", line 292, in inc_list
  print_items(filtered, output, plain_print_f=plain_print_f)
File "/home/simon/.local/lib/python3.11/site-packages/pdh/output.py", line 96, in print_items
  getattr(Output(), output)(
File "/home/simon/.local/lib/python3.11/site-packages/pdh/output.py", line 35, in plain
  plain_print_f(i)
File "/home/simon/.local/lib/python3.11/site-packages/pdh/main.py", line 275, in plain_print_f
  s += f"{i[f]}\t"
  ~^^^
KeyError: 'service.summary'

when trying to use plain output:

pdh inc ls -o plain

I don't know if that's specific to my PagerDuty setup or service.summary is just wrong, but as an initial quick fix we can just skip fields that we don't have.

Note: Committed with --no-verify as I have issues with ruff-pre-commit (doesn't work on NetBSD), but I did run ruff on the changes.

@atomicules
atomicules requested a review from mbovo as a code owner October 23, 2025 20:49
@atomicules

atomicules commented Oct 23, 2025

Copy link
Copy Markdown
Author

I can redo this and sign my commit, but doesn't stop initial discussion. Done.

For whatever reason I get this error:

```
File "/home/simon/.local/lib/python3.11/site-packages/pdh/main.py", line 292, in inc_list
  print_items(filtered, output, plain_print_f=plain_print_f)
File "/home/simon/.local/lib/python3.11/site-packages/pdh/output.py", line 96, in print_items
  getattr(Output(), output)(
File "/home/simon/.local/lib/python3.11/site-packages/pdh/output.py", line 35, in plain
  plain_print_f(i)
File "/home/simon/.local/lib/python3.11/site-packages/pdh/main.py", line 275, in plain_print_f
  s += f"{i[f]}\t"
  ~^^^
KeyError: 'service.summary'
```

when trying to use plain output:

```
pdh inc ls -o plain
```

I don't know if that's specific to my PagerDuty setup or
`service.summary` is just wrong, but as an initial quick fix we can just
skip fields that we don't have.

Note: Committed with `--no-verify` as I have issues with ruff-pre-commit
(doesn't work on NetBSD), but I did run `ruff` on the changes.
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.

1 participant