github/markup · error · ArgumentError
Can not render a nil.
Error message
Can not render a nil.
What it means
GitHub::Markup.render_s raises ArgumentError 'Can not render a nil.' when the content argument is nil. render_s is the symbol-keyed entry point (e.g. render_s(:markdown, text)), and the guard exists because the underlying renderer gems expect a String; passing nil through would surface as opaque NoMethodError/TypeError failures deep inside the renderer. The check is a fail-fast contract on the public API.
Source
Thrown at lib/github/markup.rb:51
def markup_impls
markups.values
end
def preload!
markup_impls.each(&:load)
end
def render(filename, content, symlink: false, options: {})
if (impl = renderer(filename, content, symlink: symlink))
impl.render(filename, content, options: options)
else
content
end
end
def render_s(symbol, content, options: {})
raise ArgumentError, 'Can not render a nil.' if content.nil?
if markups.key?(symbol)
markups[symbol].render(nil, content, options: options)
else
content
end
end
def markup(symbol, gem_name, regexp, languages, opts = {}, &block)
impl = GemImplementation.new(regexp, languages, gem_name, &block)
markup_impl(symbol, impl)
end
def markup_impl(symbol, impl)
if markups.key?(symbol)
raise ArgumentError, "The '#{symbol}' symbol is already defined."
end
markups[symbol] = implView on GitHub (pinned to 76e2682193)
Solutions
- Pass an empty string instead of nil when the source may be absent: render_s(:markdown, content || '').
- Guard at the boundary: skip rendering entirely when content.nil? and handle the empty case in the caller.
- If nil means 'bug', keep the exception but add context by rescuing ArgumentError and re-raising with the symbol/filename you were rendering.
Example fix
# before GitHub::Markup.render_s(:markdown, params[:body]) # params[:body] is nil => ArgumentError: Can not render a nil. # after GitHub::Markup.render_s(:markdown, params[:body].to_s)
Defensive patterns
Strategy: validation
Validate before calling
def safe_render_s(symbol, content, options: {})
return '' if content.nil? # or raise your own typed error
raise ArgumentError, 'content must be a String' unless content.is_a?(String)
GitHub::Markup.render_s(symbol, content, options: options)
end Type guard
# Narrow before calling: def renderable_content?(content) content.is_a?(String) # render_s only accepts String; nil raises 'Can not render a nil.' end
Try / catch
begin GitHub::Markup.render_s(:markdown, content) rescue ArgumentError => e raise unless e.message == 'Can not render a nil.' '' # deliberate empty output for absent bodies end
Prevention
- Normalize at the boundary: coerce with .to_s or `content || ''` as soon as data enters from params, DB rows, or file reads.
- Keep a single helper (e.g. safe_render_s) that all call sites use, so the nil policy is defined once.
- In tests, assert on nil and empty-string inputs for every render path you expose.
When it happens
Trigger: Calling GitHub::Markup.render_s(:markdown, nil), render_s(:rst, nil), etc.; passing a variable that came back nil from File.read on a missing file, a nil database column, a nil params value, or a test fixture that was never set.
Common situations: Optional body/description fields that are nil for some records; controller code doing render_s(:markdown, params[:body]) without presence checks; specs with let-it-be blocks defaulting to nil; reading files whose path was computed incorrectly so read returned nil via rescue.
Related errors
- stderr
- The '#{symbol}' symbol is already defined.
- subclasses of GitHub::Markup::Implementation must define #re
- unknown commonmarker option: #{opt.inspect}
- unknown commonmarker extension: #{ext.inspect}
AI-assisted analysis of github/markup@76e2682193 (2026-08-21).
Data as JSON: /api/errors/568e2495edfc9db2.
Report an issue: GitHub.