Commit 6ef3420b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Avoid crash when guide not found.

Reimplement Guides#each_item so that the guide doesn't get passed
to the block when loading of it had failed.

Also make Logger#warn return false to be able to return with false
right after showing warning.
parent 6b258c17
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -36,15 +36,13 @@ module JsDuck
    end

    # Modified each_item that also loads HTML for each guide
    def each_item(&block)
      unless @loaded
    def each_item
      super do |guide|
          guide[:html] = load_guide(guide)
        # Load the guide if not loaded
        guide[:html] = load_guide(guide) if guide[:html] == nil
        # Pass guide to block if it was successfully loaded.
        yield guide if guide[:html]
      end
        @loaded = true
      end

      super(&block)
    end

    # Modified to_array that excludes the :html from guide nodes
@@ -60,12 +58,13 @@ module JsDuck
    def load_guide(guide)
      in_dir = @path + "/guides/" + guide["name"]

      begin
      return Logger.instance.warn(:guide, "Guide #{in_dir} not found") unless File.exists?(in_dir)

      guide_file = in_dir + "/README.md"

      return Logger.instance.warn(:guide, "README.md not found in #{in_dir}") unless File.exists?(guide_file)

      begin
        @formatter.doc_context = {:filename => guide_file, :linenr => 0}
        name = File.basename(in_dir)
        @formatter.img_path = "guides/#{name}"
+2 −0
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ module JsDuck
      elsif !@warnings.has_key?(type)
        warn(nil, "Unknown warning type #{type}")
      end

      return false
    end

    # Formats filename and line number for output