Skip to content

Commit

Permalink
Make Playdate.Error CustomStringConvertible (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnvoor authored Aug 9, 2024
1 parent 13311c7 commit 5a351f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/PlaydateKit/Core/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public enum File {
/// (usually indicated by a thrown error from a filesystem function).
private static var lastError: Playdate.Error {
Playdate.Error(
humanReadableText: String(cString: file.geterr.unsafelyUnwrapped()!)
description: String(cString: file.geterr.unsafelyUnwrapped()!)
)
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/PlaydateKit/Core/Graphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum Graphics {
/// Returns the most recent error
private var error: Playdate.Error {
Playdate.Error(
humanReadableText: String(cString: video.getError.unsafelyUnwrapped(pointer)!)
description: String(cString: video.getError.unsafelyUnwrapped(pointer)!)
)
}
}
Expand All @@ -95,7 +95,7 @@ public enum Graphics {
public init(path: String) throws(Playdate.Error) {
var error: UnsafePointer<CChar>?
let pointer = graphics.loadBitmap.unsafelyUnwrapped(path, &error)
if let error { throw Playdate.Error(humanReadableText: String(cString: error)) }
if let error { throw Playdate.Error(description: String(cString: error)) }
self.pointer = pointer.unsafelyUnwrapped
free = true
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public enum Graphics {
public func load(from path: String) throws(Playdate.Error) {
var error: UnsafePointer<CChar>?
graphics.loadIntoBitmap.unsafelyUnwrapped(path, pointer, &error)
if let error { throw Playdate.Error(humanReadableText: String(cString: error)) }
if let error { throw Playdate.Error(description: String(cString: error)) }
}

/// Clears the bitmap, filling with the given `bgcolor`.
Expand Down Expand Up @@ -237,7 +237,7 @@ public enum Graphics {
public init(path: String) throws(Playdate.Error) {
var error: UnsafePointer<CChar>?
let pointer = graphics.loadBitmapTable.unsafelyUnwrapped(path, &error)
if let error { throw Playdate.Error(humanReadableText: String(cString: error)) }
if let error { throw Playdate.Error(description: String(cString: error)) }
self.pointer = pointer.unsafelyUnwrapped
}

Expand Down Expand Up @@ -273,7 +273,7 @@ public enum Graphics {
public func load(from path: String) throws(Playdate.Error) {
var error: UnsafePointer<CChar>?
graphics.loadIntoBitmapTable.unsafelyUnwrapped(path, pointer, &error)
if let error { throw Playdate.Error(humanReadableText: String(cString: error)) }
if let error { throw Playdate.Error(description: String(cString: error)) }
}

// MARK: Private
Expand All @@ -288,7 +288,7 @@ public enum Graphics {
public init(path: String) throws(Playdate.Error) {
var error: UnsafePointer<CChar>?
let pointer = graphics.loadFont.unsafelyUnwrapped(path, &error)
if let error { throw Playdate.Error(humanReadableText: String(cString: error)) }
if let error { throw Playdate.Error(description: String(cString: error)) }
self.pointer = pointer.unsafelyUnwrapped
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/PlaydateKit/Core/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public enum System {

/// Calls the log function, outputting an error in red to the console, then pauses execution.
public static func error(_ error: Playdate.Error) {
System.error(error.humanReadableText)
System.error(error.description)
}

/// Calls the log function.
Expand Down
4 changes: 2 additions & 2 deletions Sources/PlaydateKit/Playdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public enum Playdate {
// MARK: Public

/// An error thrown from the Playdate C API.
public struct Error: Swift.Error, @unchecked Sendable {
let humanReadableText: String
public struct Error: Swift.Error, CustomStringConvertible, @unchecked Sendable {
public let description: String
}

/// Access to the Playdate C API.
Expand Down

0 comments on commit 5a351f1

Please sign in to comment.