|
| 1 | +// Copyright 2020 Carton contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import CartonHelpers |
| 16 | + |
| 17 | +enum ToolchainError: Error, CustomStringConvertible { |
| 18 | + case directoryDoesNotExist(AbsolutePath) |
| 19 | + case invalidInstallationArchive(AbsolutePath) |
| 20 | + case invalidVersion(version: String) |
| 21 | + case invalidResponse(url: String, status: Int) |
| 22 | + case unsupportedOperatingSystem |
| 23 | + case noInstallationDirectory(path: String) |
| 24 | + |
| 25 | + var description: String { |
| 26 | + switch self { |
| 27 | + case let .directoryDoesNotExist(path): |
| 28 | + return "Directory at path \(path.pathString) does not exist and could not be created" |
| 29 | + case let .invalidInstallationArchive(path): |
| 30 | + return "Invalid toolchain/SDK archive was installed at path \(path)" |
| 31 | + case let .invalidVersion(version): |
| 32 | + return "Invalid version \(version)" |
| 33 | + case let .invalidResponse(url: url, status: status): |
| 34 | + return "Response from \(url) had invalid status \(status) or didn't contain body" |
| 35 | + case .unsupportedOperatingSystem: |
| 36 | + return "This version of the operating system is not supported" |
| 37 | + case let .noInstallationDirectory(path): |
| 38 | + return """ |
| 39 | + Failed to infer toolchain installation directory. Please make sure that \(path) exists. |
| 40 | + """ |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments