62 lines
2.7 KiB
Swift
62 lines
2.7 KiB
Swift
//
|
|
// ServerAddressError.swift
|
|
//
|
|
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
/// A validation failure while converting onboarding input into a server URL.
|
|
package enum ServerAddressError: Error, Hashable, Sendable {
|
|
/// The address field contained no non-whitespace characters.
|
|
case emptyAddress
|
|
/// The address used a URL scheme other than HTTP or HTTPS.
|
|
case unsupportedScheme(String)
|
|
/// Foundation could not parse the supplied address as URL components.
|
|
case malformedAddress
|
|
/// The parsed address did not contain a host name or IP address.
|
|
case missingHost
|
|
/// The address included credentials, which belong on the sign-in screen.
|
|
case credentialsNotAllowed
|
|
/// The address included a query string or fragment, which is not part of a server base URL.
|
|
case queryOrFragmentNotAllowed
|
|
/// The supplied port text was not an integer from 1 through 65535.
|
|
case invalidPort(String)
|
|
/// Both the address and the separate port field supplied a port.
|
|
case conflictingPorts
|
|
|
|
/// The user-facing explanation for this validation failure.
|
|
package var message: String {
|
|
switch self {
|
|
case .emptyAddress:
|
|
"Enter a server address"
|
|
case .unsupportedScheme(let scheme):
|
|
"\(scheme) is not supported. Use http or https"
|
|
case .malformedAddress:
|
|
"That server address could not be understood"
|
|
case .missingHost:
|
|
"The server address must contain a host name or IP address"
|
|
case .credentialsNotAllowed:
|
|
"Remove the username and password from the server address; sign in on the next screen instead"
|
|
case .queryOrFragmentNotAllowed:
|
|
"The server address cannot contain a query string or fragment"
|
|
case .invalidPort(let text):
|
|
"\(text) is not a valid port. Enter a number from 1 to 65535"
|
|
case .conflictingPorts:
|
|
"Specify the port in the address or in the port field, not both"
|
|
}
|
|
}
|
|
}
|