mirror of
https://github.com/whoeevee/EeveeSpotifyReborn.git
synced 2026-01-08 23:23:20 +00:00
37 lines
1.4 KiB
Swift
37 lines
1.4 KiB
Swift
// Copyright (c) 2017-2020 Shawn Moore and XMLCoder contributors
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// Created by Shawn Moore on 11/22/17.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/// Error Utilities
|
|
extension EncodingError {
|
|
/// Returns a `.invalidValue` error describing the given invalid floating-point value.
|
|
///
|
|
///
|
|
/// - parameter value: The value that was invalid to encode.
|
|
/// - parameter path: The path of `CodingKey`s taken to encode this value.
|
|
/// - returns: An `EncodingError` with the appropriate path and debug description.
|
|
static func _invalidFloatingPointValue<T: FloatingPoint>(_ value: T, at codingPath: [CodingKey]) -> EncodingError {
|
|
let valueDescription: String
|
|
if value == T.infinity {
|
|
valueDescription = "\(T.self).infinity"
|
|
} else if value == -T.infinity {
|
|
valueDescription = "-\(T.self).infinity"
|
|
} else {
|
|
valueDescription = "\(T.self).nan"
|
|
}
|
|
|
|
let debugDescription = """
|
|
Unable to encode \(valueDescription) directly in XML. \
|
|
Use XMLEncoder.NonConformingFloatEncodingStrategy.convertToString \
|
|
to specify how the value should be encoded.
|
|
"""
|
|
return .invalidValue(value, EncodingError.Context(codingPath: codingPath, debugDescription: debugDescription))
|
|
}
|
|
}
|