From 8b48e89ef318607431f1437eeec1ce0a14fa85ea Mon Sep 17 00:00:00 2001 From: Dante Soares Date: Wed, 18 Dec 2024 11:55:06 -0300 Subject: [PATCH] Fix error when there are nil headers --- app/routines/exercises/tag/assessments.rb | 6 +++--- lib/tasks/exercises/tag.rake | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/routines/exercises/tag/assessments.rb b/app/routines/exercises/tag/assessments.rb index 63e9a35c..5401b586 100644 --- a/app/routines/exercises/tag/assessments.rb +++ b/app/routines/exercises/tag/assessments.rb @@ -20,16 +20,16 @@ def exec(filename:, book_uuid:) post_indices = nil record_failures do |failures| ProcessSpreadsheet.call(filename: filename, headers: :downcase) do |headers, row, row_index| - uuid_index ||= headers.index { |header| header.include?('uuid') } + uuid_index ||= headers.index { |header| header&.include?('uuid') } raise ArgumentError, 'Could not find page UUID column' if uuid_index.nil? pre_indices ||= headers.filter_map.with_index do |header, index| - index if header.include?('pre') + index if header&.include?('pre') end raise ArgumentError, 'Could not find pre-section columns' if pre_indices.empty? post_indices ||= headers.filter_map.with_index do |header, index| - index if header.include?('post') + index if header&.include?('post') end raise ArgumentError, 'Could not find post-section columns' if post_indices.empty? diff --git a/lib/tasks/exercises/tag.rake b/lib/tasks/exercises/tag.rake index 1952f019..b520a1a8 100644 --- a/lib/tasks/exercises/tag.rake +++ b/lib/tasks/exercises/tag.rake @@ -89,11 +89,11 @@ namespace :exercises do csv << [ 'Exercise UID', 'Tags...' ] ProcessSpreadsheet.call(filename: args[:filename], headers: :downcase) do |headers, row, index| - chapter_index ||= headers.index { |header| header.include? 'chapter' } + chapter_index ||= headers.index { |header| header&.include? 'chapter' } raise ArgumentError, 'Could not find Chapter column' if chapter_index.nil? exercise_id_index ||= headers.index do |header| - header.include?('assessment') || header.include?('exercise') + header&.include?('assessment') || header&.include?('exercise') end raise ArgumentError, 'Could not find Assessment ID column' if exercise_id_index.nil?