Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import Yams
import ArgumentParser
import Utils

/// A utility for resolving and loading binary dependencies configuration files.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions Sources/Utils/GenericError.swift
Original file line number Diff line number Diff line change
@@ -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
}
}