diff --git a/Sources/BinaryDependencyManager/Utils/BinaryDependenciesConfigurationReader.swift b/Sources/BinaryDependencyManager/Utils/BinaryDependenciesConfigurationReader.swift index f5e5528..5f557f5 100644 --- a/Sources/BinaryDependencyManager/Utils/BinaryDependenciesConfigurationReader.swift +++ b/Sources/BinaryDependencyManager/Utils/BinaryDependenciesConfigurationReader.swift @@ -1,6 +1,5 @@ import Foundation import Yams -import ArgumentParser import Utils /// A utility for resolving and loading binary dependencies configuration files. @@ -53,7 +52,7 @@ public struct BinaryDependenciesConfigurationReader { public func resolveConfigurationFileURL(_ configurationFilePath: String?) throws -> URL { let configurationFileURL = resolveFilePath(configurationFilePath, variations: Self.defaultConfigurationFilenames) guard fileManager.fileExists(atPath: configurationFileURL.path) else { - throw ValidationError("No configuration file found") + throw GenericError("No configuration file found") } return configurationFileURL } @@ -87,7 +86,7 @@ public struct BinaryDependenciesConfigurationReader { // Get the contents of the file guard let dependenciesData: Data = fileManager.contents(atPath: configurationURL.path) else { - throw ValidationError("Can't get contents of configuration file at \(configurationURL.path)") + throw GenericError("Can't get contents of configuration file at \(configurationURL.path)") } // Decoder selection: Check if this is yaml, and fallback to JSONDecoder. @@ -104,9 +103,7 @@ public struct BinaryDependenciesConfigurationReader { // Check minimum required version let minimumRequiredVersion = configuration.minimumVersion ?? currentToolVersion guard currentToolVersion >= minimumRequiredVersion else { - throw ValidationError( - "\(configurationPath ?? configurationURL.lastPathComponent) requires version '\(minimumRequiredVersion)', but current version '\(currentToolVersion)' is lower." - ) + throw GenericError("\(configurationPath ?? configurationURL.lastPathComponent) requires version '\(minimumRequiredVersion)', but current version '\(currentToolVersion)' is lower.") } let dependencies = configuration.dependencies diff --git a/Sources/Utils/GenericError.swift b/Sources/Utils/GenericError.swift new file mode 100644 index 0000000..abf5976 --- /dev/null +++ b/Sources/Utils/GenericError.swift @@ -0,0 +1,18 @@ + +/// An error type that is presented to the user as an error with parsing their +/// command-line input. +public struct GenericError: Error, CustomStringConvertible { + /// The error message represented by this instance, this string is presented to + /// the user when a `ValidationError` is thrown from either; `run()`, + /// `validate()` or a transform closure. + public internal(set) var message: String + + /// Creates a new validation error with the given message. + public init(_ message: String) { + self.message = message + } + + public var description: String { + message + } +}