Module: MaRuKu::Errors

Included in:
MDElement
Defined in:
lib/maruku.rb,
lib/maruku/errors.rb

Constant Summary collapse

FRAME_WIDTH =
75

Instance Method Summary collapse

Instance Method Details

#maruku_error(s, src = nil, con = nil) ⇒ Object

Properly handles a formatting error. All such errors go through this method.

The behavior depends on `MaRuKu::Globals`. If this is `:warning`, this prints the error to stderr (or `@error_stream` if it's defined) and tries to continue. If `:on_error` is `:ignore`, this doesn't print anything and tries to continue. If it's `:raise`, this raises a MaRuKu::Exception.

By default, `:on_error` is set to `:warning`.

Parameters:

  • s (String)

    The text of the error

  • src (#describe, nil) (defaults to: nil)

    The source of the error

  • con (#describe, nil) (defaults to: nil)

    The context of the error

  • recover (String, nil) (defaults to: nil)

    Recovery text

Raises:


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/maruku/errors.rb', line 24

def maruku_error(s, src=nil, con=nil, recover=nil)
  policy = get_setting(:on_error)

  case policy
  when :ignore
  when :raise
    raise_error create_frame(describe_error(s, src, con, recover))
  when :warning
    tell_user create_frame(describe_error(s, src, con, recover))
  else
    raise "Unknown on_error policy: #{policy.inspect}"
  end
end

#maruku_recover(s, src = nil, con = nil, recover = nil) ⇒ Object

This is like #maruku_error but will never raise.


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/maruku/errors.rb', line 39

def maruku_recover(s, src=nil, con=nil, recover=nil)
  policy = get_setting(:on_error)

  case policy
  when :ignore
  when :raise, :warning
    tell_user create_frame(describe_error(s, src, con, recover))
  else
    raise "Unknown on_error policy: #{policy.inspect}"
  end
end

#raise_error(s) ⇒ Object

Raises:


51
52
53
# File 'lib/maruku/errors.rb', line 51

def raise_error(s)
  raise MaRuKu::Exception, s, caller
end

#tell_user(s) ⇒ Object


55
56
57
# File 'lib/maruku/errors.rb', line 55

def tell_user(s)
  (self.attributes[:error_stream] || $stderr) << s << "\n"
end