Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-27030

Fix undefined local variable error in draining_servers.rb

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0-alpha-3
    • 2.5.0, 3.0.0-alpha-3, 2.4.13
    • jruby, shell
    • None
    • Reviewed

    Description

      HBASE-21812 replaced a for-loop with an each block. Each block introduces a new scope, so a local variable defined inside it cannot be accessed afterwards.

        NameError: undefined local variable or method `admin' for main:Object
          getServerNames at /opt/khp/hbase/bin/draining_servers.rb:81
              addServers at /opt/khp/hbase/bin/draining_servers.rb:88
                  <main> at /opt/khp/hbase/bin/draining_servers.rb:146

       

      for i in [1, 2, 3]
        a = i
      end
      puts a
        # 3
      
      [4, 5, 6].each do |i|
        b = i
      end
      puts b
        # undefined local variable or method `b'
      

      We can define the admin local variable in the current scope beforehand, and we can still access it after the block.

       

      Attachments

        Issue Links

          Activity

            People

              junegunn Junegunn Choi
              junegunn Junegunn Choi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: