Class: NanDoc::CreateNanDocSite::SupremeStderrHack

Inherits:
Object
  • Object
show all
Defined in:
lib/nandoc/commands/create-nandoc-site.rb

Instance Method Summary collapse

Constructor Details

#initialize(real) ⇒ SupremeStderrHack

ridiculous: make a state machine that rewrites part of the error message coming from nanoc, then gets rid of itself when it’s done. This is so fragile and stupid but I really needed to get the nanoc message (“please file bug reports”) out of the error message so ppl don’t misfile bug reports there that are actually NanDoc bugs.



264
265
266
267
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 264

def initialize real
  @ui = real
  @state = :looking_for_error_header
end

Instance Method Details

#puts(*a) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 268

def puts *a
  case @state
  when :looking_for_error_header
    if a.first && a.first.include?('/!\ ERROR /!\\')
      @state = :waiting_for_end_of_error_box
      me = NanDoc::Config.option_prefix
      @ui.puts <<-HERE.gsub(/^ +/,'')
  +--- /!\\ ERROR /!\\ ----------------------------------------------+
  | An exception occured while running #{me}. If you think     |
  | this is a bug in nanDoc (likely), please report it at          |
  | <http://github.com/hipe/nandoc/issues> -- thanks!              |
  | (it is very likely a treebis patch failure)                    |
  +----------------------------------------------------------------+
     HERE
    else
      @ui.puts(*a) # probably just whitespace?
    end
  when :waiting_for_end_of_error_box
    if a.first && a.first =~ /\+-+\+/
      $stderr = @ui
      @state = :hack_failed
        # nothing should be callig our puts() method any more
    end
  when :hack_failed
    fail("hack failed")
  else
    fail("huh?")
  end
end

#write(*a) ⇒ Object



297
298
299
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 297

def write *a
  @ui.write(*a)
end