question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError in describe_location on user movement

See original GitHub issue

Hey Brandon–

I hate to open an issue on code that hasn’t been touched for two years, but I was playing python-adventure today (I recently watched your python/unix keynote and was so happy you ported adventure to python) and hit a bug.

I was going to try to do some debugging myself but I saw a few too many spoilers in the source code.

The exception didn’t crash the game but it did occasionally reoccur. I tried rerunning python-adventure with the same sequence of commands a few times but didn’t see the error again. I believe the error has to do with the random dwarf movements.

I’ve attached the markdown snippet of the first error traceback. I also have a gist of the complete game session as well as a filtered version with just my python commands.

This obviously isn’t very important, but I thought you may want to give it a look!

 >>> down
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/personal/python-adventure/adventure/prompt.py", line 18, in __repr__
    output = self.game.do_command(self.words)
  File "~/personal/python-adventure/adventure/game.py", line 437, in do_command
    self._do_command(words)
  File "~/personal/python-adventure/adventure/game.py", line 506, in _do_command
    self.dispatch_command(words)
  File "~/personal/python-adventure/adventure/game.py", line 553, in dispatch_command
    return self.do_motion(word1)
  File "~/personal/python-adventure/adventure/game.py", line 701, in do_motion
    self.move_to(move.action)
  File "~/personal/python-adventure/adventure/game.py", line 186, in move_to
    self.move_dwarves()
  File "~/personal/python-adventure/adventure/game.py", line 325, in move_dwarves
    self.describe_location()
  File "~/personal/python-adventure/adventure/game.py", line 379, in describe_location
    self.write(obj.messages[prop])
KeyError: 0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
brandon-rhodescommented, Apr 12, 2018

It never would have occurred to me to try picking up a dwarf — thanks for uncovering this, and thanks for writing up your investigation in such detail! I look forward to seeing your pull request, if you find the time to get one written!

0reactions
brandon-rhodescommented, Feb 8, 2019

I merged your PR (thanks!), and then made two improvements.

First, not needing more than one dwarf in the room, I simplified the test to do

game.dwarves[0].room = game.rooms[75]

And second, I tracked down the root problem. No objects were getting marked as is_fixed because of a bug in the import routine! So the check:

        if obj.is_fixed or len(obj.rooms) > 1:

was never triggering because objects were marked as being impossible to pick up.

Let me know if the issue now looks resolved from your end, and thanks again for letting me know about it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >
Python project throws a keyerror - Stack Overflow
I'm working on my Python assignment and am trying to convert strings into the ICAO letter codes. However, whenever the first loop of...
Read more >
How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >
How to fix Python KeyError Exceptions in simple steps?
In simple terms, when you see a KeyError, it denotes that the key you were looking for could not be found.
Read more >
Python KeyError - STechies
In Python Language, KeyError raised when an invalid key is accessed from a dictionary. Either the key user tries to access does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found