Skip to content

Commit

Permalink
refactor: create unified error for legendary metadata retrieval failure
Browse files Browse the repository at this point in the history
  • Loading branch information
vapidinfinity committed Nov 9, 2024
1 parent a2f741d commit 284b248
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 4 additions & 7 deletions Mythic/Utilities/Legendary/LegendaryInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ final class Legendary {
}

// MARK: - Methods
// TODO: FIXME: better error handling using ``UnableToRetrieveError``

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

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

switch platformString {
case "Mac": return .macOS
case "Windows": return .windows
default: throw UnableToGetPlatformError()
default: throw UnableToRetrieveError()
}
}

Expand Down Expand Up @@ -595,12 +596,8 @@ final class Legendary {
*/
static func getGameLaunchArguments(game: Mythic.Game) throws -> [String] {
let installedData = try JSON(data: Data(contentsOf: URL(filePath: "\(configLocation)/installed.json")))
guard let platformString = installedData[game.id]["platform"].string else {
throw UnableToGetPlatformError()
}

guard let arguments = installedData[game.id]["launch_parameters"].string else {
throw UnableToGetPlatformError()
throw UnableToRetrieveError()
}

return arguments.components(separatedBy: .whitespaces)
Expand Down
11 changes: 8 additions & 3 deletions Mythic/Utilities/Legendary/LegendaryInterfaceExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ extension Legendary {
case normal
case tall
}

struct UnableToGetPlatformError: LocalizedError {
var errorDescription: String? = "Mythic is unable to get the platform of this game."

enum RetrievalType {
case platform
case launchArguments
}

struct UnableToRetrieveError: LocalizedError {
var errorDescription: String? = "Mythic is unable to retrive the requested metadata for this game."
}

struct IsNotLegendaryError: LocalizedError {
Expand Down

0 comments on commit 284b248

Please sign in to comment.