Skip to content

Commit

Permalink
Fixing issue #434 (better yaml errors)
Browse files Browse the repository at this point in the history
The standard errors that happen if there are problems during page
generation are now used for yaml loading errors. It will now tell you
the file that was being processed, and the error message along with
backtrace.

Also did some reformatting in the base_tilt_handler.
  • Loading branch information
LightGuard committed Sep 26, 2014
1 parent 03fe72f commit e7411f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
47 changes: 29 additions & 18 deletions lib/awestruct/engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'awestruct/util/inflector'
require 'awestruct/util/exception_helper'
require 'awestruct/util/default_inflections'

require 'awestruct/config'
Expand Down Expand Up @@ -131,32 +132,42 @@ def load_yamls

def load_site_yaml(yaml_path, profile = nil)
if ( File.exist?( yaml_path ) )
data = YAML.load( File.read( yaml_path, :encoding => 'bom|utf-8' ) )
if ( profile )
# JP: Interpolation now turned off by default, turn it per page if needed
site.interpolate = false
profile_data = {}
data.each do |k,v|
if ( ( k == 'profiles' ) && ( ! profile.nil? ) )
profile_data = ( v[profile] || {} )
else
begin
data = YAML.load( File.read( yaml_path, :encoding => 'bom|utf-8' ) )
if ( profile )
# JP: Interpolation now turned off by default, turn it per page if needed
site.interpolate = false
profile_data = {}
data.each do |k,v|
if ( ( k == 'profiles' ) && ( ! profile.nil? ) )
profile_data = ( v[profile] || {} )
else
site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
end
end if data
site.profile = profile
profile_data.each do |k,v|
site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
end
end if data
site.profile = profile
profile_data.each do |k,v|
site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
else
data.each do |k,v|
site.send( "#{k}=", v )
end if data
end
else
data.each do |k,v|
site.send( "#{k}=", v )
end if data
rescue Exception => e
ExceptionHelper.log_building_error e, yaml_path
ExceptionHelper.mark_failed
end
end
end

def load_yaml(yaml_path)
data = YAML.load( File.read( yaml_path ) )
begin
data = YAML.load( File.read( yaml_path ) )
rescue Exception => e
ExceptionHelper.log_building_error e, yaml_path
ExceptionHelper.mark_failed
end
name = File.basename( yaml_path, '.yml' )
site.send( "#{name}=", massage_yaml( data ) )
end
Expand Down
4 changes: 2 additions & 2 deletions lib/awestruct/handlers/base_tilt_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def rendered_content(context, with_layouts=true)
rescue Exception => e
error_page = context[:page]
if error_page[:__is_layout] == true
ExceptionHelper.log_message "An error during rendering layout file #{File.join site.dir, error_page.source_path} occurred."
ExceptionHelper.log_message "An error during rendering layout file #{File.join site.dir, error_page.source_path} occurred."
else
ExceptionHelper.log_message "An error during rendering #{File.join site.dir, error_page.source_path} occurred."
ExceptionHelper.log_message "An error during rendering #{File.join site.dir, error_page.source_path} occurred."
end
ExceptionHelper.log_message "Please see #{File.join site.dir, error_page.output_path} for more information"
return ExceptionHelper.html_error_report e, error_page.source_path
Expand Down

0 comments on commit e7411f6

Please sign in to comment.