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

FakeShellOut uses OpenStruct without requiring ostruct — NameError on the transport (target-mode) path

Aperta Adatta ai principianti
#287 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
90/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
tooling

Direzione di ricerca

Inizia in lib/mixlib/shellout/helper.rb, in FakeShellOut#initialize intorno alla riga 219, quindi esegui la riproduzione in Ruby dell’issue con e senza -rostruct. Verifica che la costruzione di FakeShellOut non generi più NameError e che status.success? restituisca ancora true senza precaricare ostruct.

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

Descrizione

Description

Mixlib::ShellOut::Helper::FakeShellOut#initialize calls OpenStruct.new (lib/mixlib/shellout/helper.rb:219 on main), but no file in the gem requires ostruct. On Ruby 3.x, OpenStruct isn't loaded unless something else in the process happens to require it, so constructing a FakeShellOut raises:

lib/mixlib/shellout/helper.rb:219:in `initialize': uninitialized constant Mixlib::ShellOut::Helper::FakeShellOut::OpenStruct (NameError)

FakeShellOut is used only on the transport path of __shell_out_command (when __transport_connection is set). That's Ohai / Chef target mode over a Train transport. Local shell_out never reaches it, which is presumably why it has gone unnoticed.

Impact

Running Ohai 19.1.40 in target mode (ohai --target <uri>) against a remote Linux host, every plugin that shells out throws this NameError. Ohai catches it and logs it only at trace level (Plugin Hostname threw #<NameError: ...>), so the run exits 0 and the attributes are simply missing: hostname, machinename, ipaddress, macaddress, network.interfaces, hostnamectl. The remote host returned correct output for every underlying command over the same transport.

With ostruct preloaded (RUBYOPT=-rostruct), the same target-mode run collects all of those attributes.

Reproduction

No transport or remote host needed:

require "mixlib/shellout/helper"
res = Struct.new(:stdout, :stderr, :exit_status).new("out", "", 0)
so  = Mixlib::ShellOut::Helper::FakeShellOut.new(["true"], {}, res)
puts so.status.success?
Command Result
ruby repro.rb NameError: uninitialized constant Mixlib::ShellOut::Helper::FakeShellOut::OpenStruct
ruby -rostruct repro.rb true

Observed with Ruby 3.1.6 and mixlib-shellout 3.3.6. The require list and the OpenStruct.new call are unchanged on main (latest tag v3.4.14): helper.rb requires only ../shellout, chef-utils, chef-utils/dsl/default_paths and chef-utils/internal, and no other file under lib/ references ostruct.

Suggested fix

Add require "ostruct" unless defined?(OpenStruct) to lib/mixlib/shellout/helper.rb. Alternatively, drop OpenStruct for a small Struct, since only success? is read.

Lingua principale
Ruby
Stelle
133
Fork
73
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 chef/mixlib-shellout

Tutte le issue di chef/mixlib-shellout

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.