./lib/dolt/sinatra/actions.rb in dolt-0.7.1 vs ./lib/dolt/sinatra/actions.rb in dolt-0.8.0

- old
+ new

@@ -13,11 +13,10 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #++ -require "em_rugged" require "json" module Dolt module Sinatra module Actions @@ -34,10 +33,25 @@ body(renderer.render(:"500", { :error => error, :repository_slug => repo, :ref => ref })) + rescue Exception => err + err_backtrace = err.backtrace.map { |s| "<li>#{s}</li>" } + error_backtrace = error.backtrace.map { |s| "<li>#{s}</li>" } + + body(<<-HTML) + <h1>Fatal Dolt Error</h1> + <p> + Dolt encountered an exception, and additionally + triggered another exception trying to render the error. + </p> + <h2>Error: #{err.class} #{err.message}</h2> + <ul>#{err_backtrace.join()}</ul> + <h2>Original error: #{error.class} #{error.message}</h2> + <ul>#{error_backtrace.join()}</ul> + HTML end def raw(repo, ref, path) blob(repo, ref, path, { :template => :raw, @@ -48,23 +62,27 @@ def blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" }) actions.blob(repo, ref, path) do |err, data| next error(err, repo, ref) if !err.nil? blob = data[:blob] - next redirect(tree_url(repo, ref, path)) if !blob.is_a?(Rugged::Blob) + next redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/ response["Content-Type"] = options[:content_type] tpl_options = options[:template_options] || {} body(renderer.render(options[:template], data, tpl_options)) end end def tree(repo, ref, path) actions.tree(repo, ref, path) do |err, data| - next error(err, repo, ref) if !err.nil? - tree = data[:tree] - next redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/ - response["Content-Type"] = "text/html" - body(renderer.render(:tree, data)) + begin + next error(err, repo, ref) if !err.nil? + tree = data[:tree] + next redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/ + response["Content-Type"] = "text/html" + body(renderer.render(:tree, data)) + rescue Exception => err + error(err, repo, ref) + end end end def blame(repo, ref, path) actions.blame(repo, ref, path) do |err, data|