imathis/octopress · error · RuntimeError

Gist replied with #{data.code} for #{gist_url}

Error message

Gist replied with #{data.code} for #{gist_url}

What it means

RuntimeError raised in get_gist_from_web (gist_tag.rb:88-90) after the plugin followed 301/302 redirects and the final HTTP status is still not 200. It means the request completed but GitHub (or a proxy in between) refused to serve the raw gist at the exact URL the plugin builds: https://gist.githubusercontent.com/raw/<gist_id>/<file>. Typical codes are 404 (bad/deleted/secret gist, wrong or missing filename) or 403/5xx from proxies and rate limiting. The tag raises during Liquid rendering, so the Jekyll build fails; a successful fetch would have been written to .gist-cache.

Source

Thrown at plugins/gist_tag.rb:89

      gist      = gist.gsub bad_chars, ''
      file      = file.gsub bad_chars, ''
      md5       = Digest::MD5.hexdigest "#{gist}-#{file}"
      File.join @cache_folder, "#{gist}-#{file}-#{md5}.cache"
    end

    def get_gist_from_web(gist, file)
      gist_url = get_gist_url_for(gist, file)
      data     = get_web_content(gist_url)

      locations = Array.new
      while (data.code.to_i == 301 || data.code.to_i == 302)
        data = handle_gist_redirecting(data)
        break if locations.include? data.header['Location']
        locations << data.header['Location']
      end

      if data.code.to_i != 200
        raise RuntimeError, "Gist replied with #{data.code} for #{gist_url}"
      end

      cache(gist, file, data.body) unless @cache_disabled
      data.body
    end

    def handle_gist_redirecting(data)
      redirected_url = data.header['Location']
      if redirected_url.nil? || redirected_url.empty?
        raise ArgumentError, "GitHub replied with a 302 but didn't provide a location in the response headers."
      end

      get_web_content(redirected_url)
    end

    def get_web_content(url)
      raw_uri           = URI.parse url
      proxy             = ENV['http_proxy']

View on GitHub (pinned to 5717a50f4e)

Solutions

  1. Open https://gist.githubusercontent.com/raw/<id>/<file> in a browser and correct the gist id and filename in the tag until it loads
  2. Always pass the exact filename even for single-file gists: {% gist 1027674 gist_tag.rb %}, not {% gist 1027674 %}
  3. Make sure the gist is public and still exists (re-create or fork it under your account and update the ids)
  4. Populate .gist-cache with one successful build and commit it so CI and offline builds never hit the network
  5. Replace this vintage plugin with the maintained jekyll-gist gem or plain <script src=...> embeds

Example fix

// before
{% gist 1027674 %}

// after
{% gist 1027674 gist_tag.rb %}
Defensive patterns

Strategy: fallback

Validate before calling

# Pre-flight the exact URL the tag will request
require 'net/https'
require 'uri'

def gist_url_ok?(gist_id, file)
  uri  = URI("https://gist.githubusercontent.com/raw/#{gist_id}/#{file}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  code = http.head(uri.request_uri).code.to_i
  code >= 200 && code < 400
end

Try / catch

code = get_cached_gist(gist, file)
begin
  code ||= get_gist_from_web(gist, file)
rescue RuntimeError => e
  raise unless e.message.start_with?('Gist replied with')
  code = get_cached_gist(gist, file) ||
         "<!-- gist #{gist}/#{file} unavailable: #{e.message} -->"
end
html_output_for script_url, code

Prevention

When it happens

Trigger: Invoking {% gist <id> <file> %} where <file> is not the exact filename inside the gist; omitting the filename entirely, which makes get_gist_url_for produce a trailing-slash URL (https://gist.githubusercontent.com/raw/<id>/) that 404s; a typo'd, deleted, or secret gist id; ENV['http_proxy'] pointing at a proxy that returns 403/500; GitHub-side routing changes, since this vintage plugin hardcodes the retired /raw/<id>/<file> scheme.

Common situations: Old Octopress/Jekyll blogs whose embedded gists were deleted or made secret years later; CI builds behind corporate proxies or with no network egress; gist authors renaming or rewriting files; sites rebuilt after GitHub changed gist raw-URL routing, making every fetch 404 regardless of arguments.

Related errors


AI-assisted analysis of imathis/octopress@5717a50f4e (2026-08-21). Data as JSON: /api/errors/d2874d7511027253. Report an issue: GitHub.