Skip to content

Commit a19d2cd

Browse files
committed
Catch possible exceptions when annotating a file.
1 parent b1882bc commit a19d2cd

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

lib/annotate/annotate_models.rb

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -260,39 +260,44 @@ def remove_annotation_of_file(file_name)
260260
# :exclude_factories<Symbol>:: whether to skip modification of factory files
261261
#
262262
def annotate(klass, file, header, options={})
263-
info = get_schema_info(klass, header, options)
264-
did_annotate = false
265-
model_name = klass.name.underscore
266-
table_name = klass.table_name
267-
model_file_name = File.join(model_dir, file)
268-
269-
if annotate_one_file(model_file_name, info, options_with_position(options, :position_in_class))
270-
did_annotate = true
271-
end
263+
begin
264+
info = get_schema_info(klass, header, options)
265+
did_annotate = false
266+
model_name = klass.name.underscore
267+
table_name = klass.table_name
268+
model_file_name = File.join(model_dir, file)
269+
270+
if annotate_one_file(model_file_name, info, options_with_position(options, :position_in_class))
271+
did_annotate = true
272+
end
272273

273-
unless options[:exclude_tests]
274-
did_annotate = TEST_PATTERNS.
275-
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }.
276-
map { |pat| find_test_file(*pat) }.
277-
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_test)) }.
278-
detect { |result| result } || did_annotate
279-
end
274+
unless options[:exclude_tests]
275+
did_annotate = TEST_PATTERNS.
276+
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }.
277+
map { |pat| find_test_file(*pat) }.
278+
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_test)) }.
279+
detect { |result| result } || did_annotate
280+
end
280281

281-
unless options[:exclude_fixtures]
282-
did_annotate = FIXTURE_PATTERNS.
283-
map { |file| resolve_filename(file, model_name, table_name) }.
284-
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) }.
285-
detect { |result| result } || did_annotate
286-
end
282+
unless options[:exclude_fixtures]
283+
did_annotate = FIXTURE_PATTERNS.
284+
map { |file| resolve_filename(file, model_name, table_name) }.
285+
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_fixture)) }.
286+
detect { |result| result } || did_annotate
287+
end
287288

288-
unless options[:exclude_factories]
289-
did_annotate = FACTORY_PATTERNS.
290-
map { |file| resolve_filename(file, model_name, table_name) }.
291-
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_factory)) }.
292-
detect { |result| result } || did_annotate
293-
end
289+
unless options[:exclude_factories]
290+
did_annotate = FACTORY_PATTERNS.
291+
map { |file| resolve_filename(file, model_name, table_name) }.
292+
map { |file| annotate_one_file(file, info, options_with_position(options, :position_in_factory)) }.
293+
detect { |result| result } || did_annotate
294+
end
294295

295-
return did_annotate
296+
return did_annotate
297+
rescue Exception => e
298+
puts "Unable to annotate #{file}: #{e.message}"
299+
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
300+
end
296301
end
297302

298303
# position = :position_in_fixture or :position_in_class

0 commit comments

Comments
 (0)