{"record":{"id":"544532a80f50fda2","repo":"Shopify/liquid","slug":"errors-argument-include","errorCode":"errors.argument.include","errorMessage":"options[:locale].t(\"errors.argument.include\")","messagePattern":"options\\[:locale\\]\\.t\\(\"errors\\.argument\\.include\"\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/liquid/tags/include.rb","lineNumber":39,"sourceCode":"    prepend Tag::Disableable\n\n    FOR = 'for'\n    SYNTAX = /(#{QuotedFragment}+)(\\s+(with|#{FOR})\\s+(#{QuotedFragment}+))?(\\s+(?:as)\\s+(#{VariableSegment}+))?/o\n    Syntax = SYNTAX\n\n    attr_reader :template_name_expr, :variable_name_expr, :attributes\n\n    def initialize(tag_name, markup, options)\n      super\n      parse_with_selected_parser(markup)\n    end\n\n    def parse(_tokens)\n    end\n\n    def render_to_output_buffer(context, output)\n      template_name = context.evaluate(@template_name_expr)\n      raise ArgumentError, options[:locale].t(\"errors.argument.include\") unless template_name.is_a?(String)\n\n      partial = PartialCache.load(\n        template_name,\n        context: context,\n        parse_context: parse_context,\n      )\n\n      context_variable_name = @alias_name || template_name.split('/').last\n\n      variable = if @variable_name_expr\n        context.evaluate(@variable_name_expr)\n      else\n        context.find_variable(template_name, raise_on_not_found: false)\n      end\n\n      old_template_name = context.template_name\n      old_partial       = context.partial\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/tags/include.rb#L21-L57","documentation":"Include#render_to_output_buffer raises ArgumentError when the evaluated template name expression is not a String at render time. Unlike the syntax errors this occurs during rendering, meaning the {% include %} tag parsed fine but resolved to a non-string (nil, Integer, Array, etc.).","triggerScenarios":"{% include some_var %} where some_var evaluates to nil or a non-string (e.g. a number from a drop or assign); {% include product.id %} where id is an integer; a variable that was never assigned so it evaluates to nil.","commonSituations":"Dynamically choosing partials from variables that may be unassigned; passing numeric IDs as include names; Shopify/Liquid templates with optional variables that are empty at render time.","solutions":["Ensure the expression resolves to a String: assign a string first, e.g. {% assign name = product.template_name %}{% include name %}","Guard with {% if some_var %}{% include some_var %}{% endif %} or provide a default via the assign/filter","If using a numeric key, convert to a string in the assigned value"],"exampleFix":"// before\n{% include product.id %}\n// after\n{% assign partial = product.slug %}\n{% if partial %}{% include partial %}{% endif %}","handlingStrategy":"type-guard","validationCode":"name = context.evaluate(template_name_expr)\nraise ArgumentError, 'include name must be a String' unless name.is_a?(String) && !name.empty?","typeGuard":"def string_partial_name?(value)\n  value.is_a?(String) && !value.empty?\nend","tryCatchPattern":"begin\n  output = template.render(assigns)\nrescue Liquid::ArgumentError => e\n  if e.message.include?('errors.argument.include')\n    logger.warn(\"include resolved to non-string: #{e.message}\")\n    ''\n  else\n    raise\n  end\nend","preventionTips":["Assign include names to variables first and ensure they are strings","Guard dynamic includes with {% if %} checks so nil names never render","Avoid including numeric IDs; convert to slug/string names upstream"],"tags":["ruby","liquid","argument-error","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}