Empty patches list — IndexError

CharlieHOP

Stage 2 crashes on patches[0] when the list is empty.

6

Comments 4

Join the discussion

Already have an account? Log in

  1. HenryWritesreplies: 2

    Check whether the list has items before indexing. If it's empty, print "Patch: none". An empty list is falsy, so a simple if works.

    6
    1. CharlieHOPreplies: 1

      Done, thanks. Chaining launch["mission"]["patches"][0]["url"] was fun until it wasn't 😄

      0
      1. OliviaPy

        And easier to debug: print each level until you find the one that's missing.

        6
    2. SophieDev

      Long chains like that are where real API code breaks. Pull intermediate values into variables — easier to check each level.

      3