Merge pull request #4709 from aignatov-bio/ai-sci-7572-fix-label-template-error-handling

Fix label template error handling [SCI-7572]
This commit is contained in:
aignatov-bio 2022-12-13 09:05:16 +01:00 committed by GitHub
commit fa6311382e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,10 @@
# frozen_string_literal: true
module LabelTemplates
class ColumnNotFoundError < StandardError; end
class LogoNotFoundError < StandardError; end
class LogoParamsError < StandardError; end
class RepositoryRowService
class UnsupportedKeyError < StandardError; end
class ColumnNotFoundError < StandardError; end
class LogoNotFoundError < StandardError; end
MAX_PRINTABLE_ITEM_NAME_LENGTH = 64
@ -21,7 +19,9 @@ module LabelTemplates
keys = @label_template.content.scan(/(?<=\{\{).*?(?=\}\})/).uniq
label = keys.reduce(@label_template.content.dup) do |rendered_content, key|
rendered_content.gsub!(/\{\{#{key}\}\}/, fetch_value(key))
rescue ColumnNotFoundError, LogoNotFoundError => e
rescue LabelTemplates::ColumnNotFoundError,
LabelTemplates::LogoNotFoundError,
LabelTemplates::LogoParamsError => e
errors.push(e)
rendered_content
end
@ -49,7 +49,7 @@ module LabelTemplates
when /^c_(.*)/
name = Regexp.last_match(1)
unless @repository_columns.include?(name)
raise ColumnNotFoundError, I18n.t('label_templates.repository_row.errors.column_not_found')
raise LabelTemplates::ColumnNotFoundError, I18n.t('label_templates.repository_row.errors.column_not_found')
end
fetch_custom_column_value(name)
@ -64,12 +64,12 @@ module LabelTemplates
when /^LOGO/
logo(key)
else
raise ColumnNotFoundError, I18n.t('label_templates.repository_row.errors.column_not_found')
raise LabelTemplates::ColumnNotFoundError, I18n.t('label_templates.repository_row.errors.column_not_found')
end
end
def logo(_key)
raise LogoNotFoundError, I18n.t('label_templates.repository_row.errors.logo_not_supported')
raise LabelTemplates::LogoNotFoundError, I18n.t('label_templates.repository_row.errors.logo_not_supported')
end
end
end