Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed May 28, 2017
1 parent 5818096 commit 7ae20f5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Sources/Parsers/ColorsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import PathKit
public enum ColorsParserError: Error, CustomStringConvertible {
case invalidHexColor(string: String, key: String?)
case invalidFile(reason: String)
case unsupportedFileType
case unsupportedFileType(supported: [String])

public var description: String {
switch self {
case .invalidHexColor(string: let string, key: let key):
case .invalidHexColor(let string, let key):
let keyInfo = key.flatMap { " for key \"\($0)\"" } ?? ""
return "error: Invalid hex color \"\(string)\" found\(keyInfo)."
case .invalidFile(reason: let reason):
case .invalidFile(let reason):
return "error: Unable to parse file. \(reason)"
case .unsupportedFileType:
return "error: Unsupported file type. The supported file types are CLR, TXT, XML and JSON"
case .unsupportedFileType(let supported):
return "error: Unsupported file type. The supported file types are: \(supported.joined(separator: ", "))"
}
}
}
Expand All @@ -45,7 +45,7 @@ public final class ColorsFileParser {

public func parseFile(at path: Path) throws {
guard let parserType = parsers[path.extension?.lowercased() ?? ""] else {
throw ColorsParserError.unsupportedFileType
throw ColorsParserError.unsupportedFileType(supported: Array(parsers.keys))
}

let parser = parserType.init()
Expand Down

0 comments on commit 7ae20f5

Please sign in to comment.