{"record":{"id":"568e2495edfc9db2","repo":"github/markup","slug":"can-not-render-a-nil","errorCode":null,"errorMessage":"Can not render a nil.","messagePattern":"Can not render a nil\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/github/markup.rb","lineNumber":51,"sourceCode":"\n    def markup_impls\n      markups.values\n    end\n\n    def preload!\n      markup_impls.each(&:load)\n    end\n\n    def render(filename, content, symlink: false, options: {})\n      if (impl = renderer(filename, content, symlink: symlink))\n        impl.render(filename, content, options: options)\n      else\n        content\n      end\n    end\n\n    def render_s(symbol, content, options: {})\n      raise ArgumentError, 'Can not render a nil.' if content.nil?\n\n      if markups.key?(symbol)\n        markups[symbol].render(nil, content, options: options)\n      else\n        content\n      end\n    end\n\n    def markup(symbol, gem_name, regexp, languages, opts = {}, &block)\n      impl = GemImplementation.new(regexp, languages, gem_name, &block)\n      markup_impl(symbol, impl)\n    end\n\n    def markup_impl(symbol, impl)\n      if markups.key?(symbol)\n        raise ArgumentError, \"The '#{symbol}' symbol is already defined.\"\n      end\n      markups[symbol] = impl","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/github/markup/blob/76e2682193828b98471b3a071edf4db0590ccacb/lib/github/markup.rb#L33-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nGitHub::Markup.render_s(:markdown, params[:body])\n# params[:body] is nil => ArgumentError: Can not render a nil.\n\n# after\nGitHub::Markup.render_s(:markdown, params[:body].to_s)","handlingStrategy":"validation","validationCode":"def safe_render_s(symbol, content, options: {})\n  return '' if content.nil?            # or raise your own typed error\n  raise ArgumentError, 'content must be a String' unless content.is_a?(String)\n  GitHub::Markup.render_s(symbol, content, options: options)\nend","typeGuard":"# Narrow before calling:\ndef renderable_content?(content)\n  content.is_a?(String) # render_s only accepts String; nil raises 'Can not render a nil.'\nend","tryCatchPattern":"begin\n  GitHub::Markup.render_s(:markdown, content)\nrescue ArgumentError => e\n  raise unless e.message == 'Can not render a nil.'\n  '' # deliberate empty output for absent bodies\nend","preventionTips":["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."],"tags":["nil-safety","argument-validation","ruby","github-markup"],"backgroundTag":"nil-argument","analyzedSha":"76e2682193828b98471b3a071edf4db0590ccacb","analyzedAt":"2026-08-21T19:16:29.859Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}