Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the error message for an invalid version more user-friendly #942

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

TTOzzi
Copy link
Contributor

@TTOzzi TTOzzi commented Feb 21, 2025

The error message displayed when an invalid version is entered in the .swift-format configuration was not user-friendly.
Currently, only version 1 exists, but in preparation for the possibility of more versions being introduced in the future (such as #833..?), I improved the message to help users easily identify and correct invalid version inputs.
Additionally, I modified the error message to display the path using relativePath.

Below is the output when setting the version in the configuration file to 2.
before:
before

after:
after

@TTOzzi TTOzzi force-pushed the configuration_decoding_error branch 2 times, most recently from dd360f9 to b3cc76c Compare February 22, 2025 01:53
@@ -21,6 +21,13 @@ import Foundation
/// with the previous format.
internal let highestSupportedConfigurationVersion = 1

private struct ConfigurationDecodingError: LocalizedError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of introducing a new error type, can you add this as a new case to https://github.com/swiftlang/swift-format/blob/main/Sources/SwiftFormat/API/SwiftFormatError.swift? Something like unsupportedConfigurationVersion(Int, highestSupported: Int).

You'll need to add it as an allowed API breakage to https://github.com/swiftlang/swift-format/blob/main/api-breakages.txt, but that's fine because swift-format doesn't promise a resilient API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh there's already an error type defined! Thanks for the feedback.

@TTOzzi TTOzzi force-pushed the configuration_decoding_error branch from b3cc76c to 5773d64 Compare February 24, 2025 15:59
@TTOzzi TTOzzi requested a review from allevato February 24, 2025 15:59
Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@allevato allevato merged commit 8cb0e35 into swiftlang:main Feb 24, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants