Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

TypeError: no implicit conversion of Array into String when checking size of Array in the test expect block

Aperta
#68 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby
Ambito
testing-qa

Direzione di ricerca

Inizia con il test Ruby di esempio e il blocco expect che chiama taskArray.count, quindi eseguilo con logstash -e "the file" -t per riprodurre il TypeError. Traccia la gestione di expect da parte del framework di test e verifica che il controllo della dimensione dell’array estratto venga completato correttamente senza l’eccezione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Logstash information:

Please include the following information:

  1. Logstash version (e.g. bin/logstash --version) 8.9.1
  2. Logstash installation source (e.g. built from source, with a package manager: DEB/RPM, expanded from tar or zip archive, docker) RPM
  3. How is Logstash being run (e.g. as a service/service manager: systemd, upstart, etc. Via command line, docker/kubernetes) service most of the time, command line for running ruby tests
  4. How was the Logstash Plugin installed sudo yum install logstash

JVM (e.g. java -version): Open JDK 11.0.19

OS version (uname -a if on a Unix-like system): Red Hat Linux 7.x

Description of the problem including expected versus actual behavior: Cannot check size/length of array in the expect block of the testing framework. Error is {"exception"=>"#<TypeError: no implicit conversion of Array into String>"

Steps to reproduce:

Please include a minimal but complete recreation of the problem,
including (e.g.) pipeline definition(s), settings, locale, etc. The easier
you make for us to reproduce it, the more likely that somebody will take the
time to look at it.

  1. Create a .rb file with the filter and test methods
  2. Filter should instantiate JSON array and set it in the event - eg. event.set("myarray", the_array)
  3. Implement in_event block in the test with example JSON that includes an array.
  4. Implement expect block to check size of the array which was set in the filter event. None of the usual methods work: length, size, count
  5. Execute test on command line. eg. logstash -e "the file" -t
  6. Above error is reported.

Sample code):

def filter(event)
  taskArray = Array.new
  errorElements = event.get("[error]")
  if errorElements.is_a? Array
    errorElements.each_index { |x|
      taskArray.push(errorElements[x]["task"])
    }
  end
  event.set("error_task_array", taskArray)
  return [event]
end

test "get task array" do
  in_event {
    {
      "name":"job1",
      "error":[
         {
         "task":"75fc",
         "message":{
            "ietf-restconf:errors":{
               "error":[
                  {
                     "error-type":"application",
                     "error-tag":"malformed-message",
                     "error-path":"/pathto/problem",
                     "error-message":"missing element: name in thepath"
                  }
               ]
            }
         },
         "timestamp":1.695060733555E+12
        },
        {
         "task":"job",
         "message":"Job has no available transitions. 6649, cb04, f5dd could have led to the workflow end task, but did not. These tasks performed in a way that the end of the workflow could not be reached.",
         "timestamp":1.69506073357E+12
        }
      ]
    }
  }

 expect("extracts the task array") do |events|
    taskArray = events[0].get(["error_task_array"])
    taskArray.count == 2
  end # expect

end # test

Lingua principale
Ruby
Stelle
18
Fork
32
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di logstash-plugins/logstash-filter-ruby

Tutte le issue di logstash-plugins/logstash-filter-ruby

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.