Skip to content

Commit 284b248

Browse files
committed
refactor: create unified error for legendary metadata retrieval failure
1 parent a2f741d commit 284b248

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Mythic/Utilities/Legendary/LegendaryInterface.swift

+4-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ final class Legendary {
5959
}
6060

6161
// MARK: - Methods
62+
// TODO: FIXME: better error handling using ``UnableToRetrieveError``
6263

6364
/**
6465
Executes Legendary's command-line process with the specified arguments and handles its output and input interactions.
@@ -435,13 +436,13 @@ final class Legendary {
435436

436437
let installedData = try JSON(data: Data(contentsOf: URL(filePath: "\(configLocation)/installed.json")))
437438
guard let platformString = installedData[game.id]["platform"].string else {
438-
throw UnableToGetPlatformError()
439+
throw UnableToRetrieveError()
439440
}
440441

441442
switch platformString {
442443
case "Mac": return .macOS
443444
case "Windows": return .windows
444-
default: throw UnableToGetPlatformError()
445+
default: throw UnableToRetrieveError()
445446
}
446447
}
447448

@@ -595,12 +596,8 @@ final class Legendary {
595596
*/
596597
static func getGameLaunchArguments(game: Mythic.Game) throws -> [String] {
597598
let installedData = try JSON(data: Data(contentsOf: URL(filePath: "\(configLocation)/installed.json")))
598-
guard let platformString = installedData[game.id]["platform"].string else {
599-
throw UnableToGetPlatformError()
600-
}
601-
602599
guard let arguments = installedData[game.id]["launch_parameters"].string else {
603-
throw UnableToGetPlatformError()
600+
throw UnableToRetrieveError()
604601
}
605602

606603
return arguments.components(separatedBy: .whitespaces)

Mythic/Utilities/Legendary/LegendaryInterfaceExt.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ extension Legendary {
2222
case normal
2323
case tall
2424
}
25-
26-
struct UnableToGetPlatformError: LocalizedError {
27-
var errorDescription: String? = "Mythic is unable to get the platform of this game."
25+
26+
enum RetrievalType {
27+
case platform
28+
case launchArguments
29+
}
30+
31+
struct UnableToRetrieveError: LocalizedError {
32+
var errorDescription: String? = "Mythic is unable to retrive the requested metadata for this game."
2833
}
2934

3035
struct IsNotLegendaryError: LocalizedError {

0 commit comments

Comments
 (0)