Skip to content

Commit

Permalink
Throw error when a showstopper error happens while reading a remote s…
Browse files Browse the repository at this point in the history
…ong in nextcloud backend

This way we stop enumeration and tell the application that the container is not, in fact, fully scanned

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Jun 25, 2024
1 parent 39be708 commit b425858
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions HarmonyKit/Backend/Backend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public let BackendNewScanRequiredNotification = Notification.Name("BackendNewSca

public enum ScanError: Error {
case generalError(String)
case remoteReadError(String)
}

public protocol Backend: Identifiable, Hashable, ObservableObject {
Expand Down
8 changes: 3 additions & 5 deletions HarmonyKit/Backend/Nextcloud/NextcloudBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,11 @@ public class NextcloudBackend: NSObject, Backend, NKCommonDelegate, URLSessionWe
) async throws -> Song? {
// Process received file
guard let songUrl = URL(string: receivedFileUrl) else {
logger.error("Received serverUrl for \(receivedFileUrl) is invalid")
return nil
throw ScanError.remoteReadError("Received invalid song URL \(receivedFileUrl)")
}

guard fileHasPlayableExtension(fileURL: songUrl) else {
logger.info("File at \(songUrl) is not a playable song file, skip")
logger.info("File at \(songUrl) is not a playable song file, skipping.")
return nil
}

Expand All @@ -463,8 +462,7 @@ public class NextcloudBackend: NSObject, Backend, NKCommonDelegate, URLSessionWe
fetchSession: ncKit.sessionManager,
fetchHeaders: ncKit.nkCommonInstance.getStandardHeaders(options: .init())
) else {
logger.error("Could not create song from \(receivedFileUrl)")
return nil
throw ScanError.remoteReadError("Could not create song from \(receivedFileUrl)")
}

logger.debug("Acquired valid song: \(songUrl)")
Expand Down

0 comments on commit b425858

Please sign in to comment.