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

File.contents will crash for files that cannot be read later, when initialised with init(pathDeferringReading:) #765

Closed
mildm8nnered opened this issue Mar 18, 2023 · 0 comments · Fixed by #766

Comments

@mildm8nnered
Copy link
Contributor

mildm8nnered commented Mar 18, 2023

This can be seen by running SwiftLint against swift

brew install swiftlint
git clone https://github.com/apple/swift
cd swift
swiftlint

The problem file is ./validation-test/IDE/crashers_fixed/033-swift-identifier-isoperatorslow.swift , which cannot be interpreted as UTF-8

% swiftlint  ./validation-test/IDE/crashers_fixed/033-swift-identifier-isoperatorslow.swift          
Linting Swift files at paths ./validation-test/IDE/crashers_fixed/033-swift-identifier-isoperatorslow.swift
Linting '033-swift-identifier-isoperatorslow.swift' (1/1)
SourceKittenFramework/File.swift:20: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=261 "The file “033-swift-identifier-isoperatorslow.swift” couldn’t be opened using text encoding Unicode (UTF-8)." UserInfo={NSFilePath=/Users/martin.redington/Documents/Hudl/Source/swift/validation-test/IDE/crashers_fixed/033-swift-identifier-isoperatorslow.swift, NSStringEncoding=4}
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
zsh: trace trap  ../Sportscode64/Pods/SwiftLint/swiftlint 

See realm/SwiftLint#4821

But actually, if the file cannot be read for any reason, then this will cause a crash

touch t.swift
chmod -r t.swift
swiftlint  t.swift
Linting Swift files at paths t.swift
Linting 't.swift' (1/1)
SourceKittenFramework/File.swift:20: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=257 "The file “t.swift” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Users/martin.redington/Documents/Hudl/Source/SourceKitten/t.swift, NSUnderlyingError=0x600002a48210 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
zsh: trace trap  ../Sportscode64/Pods/SwiftLint/swiftlint t.swift
@mildm8nnered mildm8nnered changed the title File.contents will crash for files that cannot be parsed as UTF-8, when initialised with init(pathDeferringReading:) File.contents will crash for files that cannot be read later, when initialised with init(pathDeferringReading:) Mar 18, 2023
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 a pull request may close this issue.

1 participant