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
8 changes: 3 additions & 5 deletions Sources/SwiftFormat/API/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,9 @@ public struct Configuration: Codable, Equatable {
// If the version number is not present, assume it is 1.
self.version = try container.decodeIfPresent(Int.self, forKey: .version) ?? 1
guard version <= highestSupportedConfigurationVersion else {
throw DecodingError.dataCorruptedError(
forKey: .version,
in: container,
debugDescription:
"This version of the formatter does not support configuration version \(version)."
throw SwiftFormatError.unsupportedConfigurationVersion(
version,
highestSupported: highestSupportedConfigurationVersion
)
}

Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftFormat/API/SwiftFormatError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public enum SwiftFormatError: LocalizedError {
/// An error happened while dumping the tool's configuration.
case configurationDumpFailed(String)

/// The provided configuration version is not supported by this version of the formatter.
case unsupportedConfigurationVersion(Int, highestSupported: Int)

public var errorDescription: String? {
switch self {
case .fileNotReadable:
Expand All @@ -43,6 +46,9 @@ public enum SwiftFormatError: LocalizedError {
return "experimental feature '\(name)' was not recognized by the Swift parser"
case .configurationDumpFailed(let message):
return "dumping configuration failed: \(message)"
case .unsupportedConfigurationVersion(let version, let highestSupported):
return
"This version of the formatter does not support configuration version \(version). The highest supported version is \(highestSupported)."
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/swift-format/Frontend/Frontend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Frontend {
// Fall through to the default return at the end of the function.
} catch {
diagnosticsEngine.emitError(
"Unable to read configuration for \(swiftFileURL.path): \(error.localizedDescription)"
"Unable to read configuration for \(swiftFileURL.relativePath): \(error.localizedDescription)"
)
return nil
}
Expand All @@ -116,7 +116,7 @@ class Frontend {
}
} catch {
diagnosticsEngine.emitError(
"Unable to read configuration for \(cwd): \(error.localizedDescription)"
"Unable to read configuration for \(cwd.relativePath): \(error.localizedDescription)"
)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions api-breakages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

API breakage: constructor FileIterator.init(urls:followSymlinks:) has been removed
API breakage: enumelement SwiftFormatError.configurationDumpFailed has been added as a new enum case
API breakage: enumelement SwiftFormatError.unsupportedConfigurationVersion has been added as a new enum case