Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 8 additions & 68 deletions Sources/CLI/client/AppleDocumentationClient+Error.swift
Original file line number Diff line number Diff line change
@@ -1,73 +1,13 @@
import Foundation

extension DefaultAppleDocumentationClient {
enum Error: Swift.Error, Equatable, LocalizedError, ExpectedCommandError {
case httpStatus(Int)
case invalidResponse
case technologyNotFound(String)
case typeNotFound(
name: String,
technology: String,
suggestion: DocumentationType?,
technologyURL: String
)
case unsupportedTechnology(name: String, url: String)

var isExpected: Bool {
switch self {
case .technologyNotFound, .typeNotFound, .unsupportedTechnology:
return true
case .httpStatus, .invalidResponse:
return false
}
enum AppleDocumentationClientError: Error, Equatable, LocalizedError {
case httpStatus(Int)
case invalidResponse

var errorDescription: String? {
switch self {
case .httpStatus(let status): return "Apple documentation returned HTTP status \(status)."
case .invalidResponse: return "Apple documentation returned an invalid response."
}

var errorDescription: String? {
switch self {
case .httpStatus(let statusCode):
return "Apple documentation returned HTTP status \(statusCode)."
case .invalidResponse:
return "Apple documentation returned an invalid response."
case .technologyNotFound(let technology):
return """
Apple documentation technology '\(technology)' was not found.

Browse available technologies:
apple-docs technologies list
"""
case .typeNotFound(let name, let technology, let suggestion, let technologyURL):
var sections = ["No Apple documentation found for '\(name)' in \(technology)."]
if let suggestion {
sections.append(
"""
Did you mean:
\(suggestion.name)
\(suggestion.url)
"""
)
}
sections.append(
"""
Browse available types:
apple-docs types list --technology "\(technology)"
\(technologyURL)
"""
)
return sections.joined(separator: "\n\n")
case .unsupportedTechnology(let name, let url):
return """
Type retrieval is unavailable for \(name).

Continue in the technology documentation:
\(url)
"""
}
}
}

struct ResolvedTechnology {
let name: String
let documentationSlug: String?
let url: String
}
}
Loading
Loading