From 3e00e294a0d33417514eae6848890f5331d98201 Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 17 Aug 2022 10:07:49 -0400 Subject: [PATCH] Convert to barfing. --- .../Atoms/Views/Label/LabelAttributeImageModel.swift | 5 ++--- .../Atoms/Views/Label/LabelAttributeModel.swift | 7 +++---- MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift | 11 ++++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeImageModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeImageModel.swift index 2f8235e0..d6ec1b74 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeImageModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeImageModel.swift @@ -40,11 +40,10 @@ class LabelAttributeImageModel: LabelAttributeModel { // MARK: - Validations //-------------------------------------------------- - public override func validateInRange(of text: String) -> MolecularError? { + public override func validateInRange(of text: String) throws { guard location >= 0 && location <= text.count else { - return MolecularError.validationError("Attribute starting location \(location) is out of bounds for '\(text)'.") + throw MolecularError.validationError("Attribute starting location \(location) is out of bounds for '\(text)'.") } - return nil } //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeModel.swift index 590e79b9..88192720 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeModel.swift @@ -48,16 +48,15 @@ // MARK: - Validations //-------------------------------------------------- - public func validateInRange(of text: String) -> MolecularError? { + public func validateInRange(of text: String) throws { // Prevent invalid starting locations. guard location >= 0 && location <= text.count else { - return MolecularError.validationError("Attribute starting location \(location) is out of bounds for '\(text)'.") + throw MolecularError.validationError("Attribute starting location \(location) is out of bounds for '\(text)'.") } // Prevent lengths extending beyond the bounds of the string. guard length + location <= text.count else { - return MolecularError.validationError("Attribute length \(length) starting at \(location) is out of bounds for '\(text)'.") + throw MolecularError.validationError("Attribute length \(length) starting at \(location) is out of bounds for '\(text)'.") } - return nil } //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift index f23b3f90..10e6a4e5 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift @@ -66,13 +66,10 @@ // MARK: - Validations //-------------------------------------------------- - public func validate(_ attributes: [LabelAttributeModel]) -> MolecularError? { + public func validate(_ attributes: [LabelAttributeModel]) throws { for attribute in attributes { - if let molecularError = attribute.validateInRange(of: text) { - return molecularError - } + try attribute.validateInRange(of: text) } - return nil } //-------------------------------------------------- @@ -97,8 +94,8 @@ shouldMaskRecordedView = try typeContainer.decodeIfPresent(Bool.self, forKey: .shouldMaskRecordedView) ?? false // Later make protocol based validate outside of decoding? - if let attributes = attributes, let error = validate(attributes) { - throw error + if let attributes = attributes { + try validate(attributes) } }