Repository navigation
Closed
Labels
bugUnexpected and reproducible misbehavior.
Description
New Issue Checklist
- I've Updated SwiftLint to the latest version.
- I've searched for existing GitHub issues.
Bug Description
Force unwrap in withUnsafeFileSystemRepresentation (Source/SwiftLintCore/Extensions/URL+SwiftLint.swift) causes crash.
Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.
$ swiftlintWorkaround was to exclude some paths that crashed the app:
excluded:
- App.xcodeproj
- Resources/Settings.bundle
Environment
- SwiftLint version 0.63.0
- Xcode version 16.2, 16.3
- Installation method used Homebrew
- Configuration file:
disabled_rules:
- dynamic_inline
- private_unit_test
- type_body_length
- valid_ibinspectable
- strict_fileprivate
- function_default_parameter_at_end
- multiline_function_chains
- type_name
- conditional_returns_on_newline
- closure_body_length
opt_in_rules:
- closure_spacing
- convenience_type
- discouraged_object_literal
- empty_string
- fallthrough
- fatal_error_message
- first_where
- multiline_arguments
- multiline_parameters
- overridden_super_call
- override_in_extension
- required_enum_case
- vertical_parameter_alignment_on_call
- yoda_condition
- array_init
- explicit_init
- function_default_parameter_at_end
- redundant_nil_coalescing
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- discouraged_optional_boolean
- empty_collection_literal
- empty_count
- file_name_no_space
- flatmap_over_map_reduce
- identical_operands
- joined_default_parameter
- last_where
- literal_expression_end_indentation
- nslocalizedstring_key
- operator_usage_whitespace
- pattern_matching_keywords
- private_action
- private_outlet
- prohibited_super_call
- reduce_into
- redundant_type_annotation
- sorted_first_last
- static_operator
- toggle_bool
- unavailable_function
- unneeded_parentheses_in_closure_argument
- vertical_whitespace_closing_braces
- closure_end_indentation
- nimble_operator
- weak_delegate
- private_swiftui_state
analyzer_rules:
- unused_declaration
- unused_import
excluded:
- Frameworks
- Scripts
- node_modules
- Sources/Generated/
- Tests
closing_brace:
severity: error
closure_end_indentation:
severity: error
colon:
severity: error
flexible_rightx_spacing: false
apply_to_dictionaries: true
comma:
severity: error
control_statement:
severity: error
cyclomatic_complexity:
- 7 #warning
- 8 #error
empty_count:
severity: error
empty_parameters:
severity: error
explicit_init:
severity: error
file_length:
- 300 #warning
- 500 #error
force_cast:
severity: error
force_try:
severity: error
function_body_length:
- 50 #warning
- 70 #error
function_parameter_count:
- 5 #warning
- 6 #error
implicit_getter:
severity: error
large_tuple:
- 3 #warning
- 5 #error
leading_whitespace:
severity: error
legacy_cggeometry_functions:
severity: error
legacy_constant:
severity: error
legacy_constructor:
severity: error
legacy_nsgeometry_functions:
severity: error
line_length:
ignores_comments: true
warning: 120
error: 120
mark:
severity: error
nesting:
severity: error
nimble_operator:
severity: error
opening_brace:
severity: error
operator_usage_whitespace:
severity: error
operator_whitespace:
severity: error
overridden_super_call:
severity: error
redundant_nil_coalescing:
severity: error
redundant_optional_initialization:
severity: error
redundant_string_enum_value:
severity: error
redundant_void_return:
severity: error
return_arrow_whitespace:
severity: error
syntactic_sugar:
severity: error
todo:
severity: warning
trailing_comma:
severity: error
trailing_newline:
severity: error
trailing_semicolon:
severity: error
trailing_whitespace:
severity: error
unused_closure_parameter:
severity: warning
identifier_name:
min_length: 2
severity: error
vertical_parameter_alignment:
severity: error
vertical_whitespace:
severity: error
void_return:
severity: error
weak_delegate:
severity: error
first_where:
severity: error
private_action:
severity: error
private_outlet:
severity: error
closure_spacing:
severity: error
array_init:
severity: error
statement_position:
severity: error
unused_enumerated:
severity: error
vertical_parameter_alignment_on_call:
severity: error
empty_string:
severity: error
unneeded_break_in_switch:
severity: error
fatal_error_message:
severity: error
empty_parentheses_with_trailing_closure:
severity: error
contains_over_first_not_nil:
severity: error
private_swiftui_state:
severity: error
custom_rules:
environment_private:
name: "Private SwiftUI Environment"
regex: "\\@Environment\\s*var"
message: "SwiftUI @Environment variables should always be marked private."
severity: error
binding_private:
name: "Private SwiftUI Binding"
regex: "\\@Binding\\s*var"
message: "SwiftUI @Binding variables should always be marked private."
severity: errorMetadata
Metadata
Assignees
Labels
bugUnexpected and reproducible misbehavior.
Activity
SimplyDanny commentedon Jan 7, 2026
Are you able to scope the crash to a single file (path)? That would help a lot.
@compnerd: For your interest. Do you have an idea for which paths this call would fail?
compnerd commentedon Jan 7, 2026
It is possible that the file path is not valid utf8, empty, or not a file URL. Those are the three cases that immediately come to mind.
liliomk-supercharge commentedon Jan 7, 2026
I built the project locally and put in some logging into filepath:
When the file had no issues, the log looked as follows:
When there was an issue, either only the filename or the parent directory path was printed.
Sorry, I can't give you anything easily reproducible, but as far as I could see, there was nothing special with the files/directories this has failed with.
I'll check whether calling
standardizedFileURLfixes the issue. In any case I think replacing the force unwrap with an optional would be a bit better.SimplyDanny commentedon Jan 9, 2026
@liliomk-supercharge: Can you track down which part of the code calls
url.filepathwhen it fails? We need to understand how the URL was constructed and do it right.liliomk-supercharge commentedon Jan 12, 2026
liliomk-supercharge commentedon Jan 12, 2026
Some more info:
macOS 15.7.1
Modified code to:
And before failing I got the following output:
compnerd commentedon Jan 12, 2026
Hmm, path being empty is the cause of the issue. For a file URL, I would expect
pathto be the actual path (relative or absolute). I wonder how this path is being modified after creation.SimplyDanny commentedon Jan 14, 2026
@liliomk-supercharge: Could you check whether the current
mainfixes the issue for you? I made a change for another #6425 and I'm wondering if it might avoid this crash too.Other than that, I'm not able to create a test cases to reproduce this error. URL seems to be very safe to use normally.
liliomk-supercharge commentedon Jan 14, 2026
@SimplyDanny
mainfromcommit 35e3d0c6f473fdd58d4821d3d93258e899c1832fdidn't solve it. I attached a debug stacktrace.lldb.txt
liliomk-supercharge commentedon Jan 14, 2026
@SimplyDanny @compnerd I attached a minimal example.
App-minimal.zip
Instructions:
Results:
SwiftLintCore/URL+SwiftLint.swift:5: Fatal error: Unexpectedly found nil while unwrapping an Optional valueSimplyDanny commentedon Jan 14, 2026
The problem is that the
:inandroidx.core:core-bundle.plistis actually not a colon. It's only how many fonts represent it. It really is a Unicode character from the Private Use Area to avoid using colons as they might be treated specially depending on the OS.It seems like there was an issue with that in older versions of Foundation, but now, with the latest one, it works. Not sure how to workaround the issue even for older versions. Avoiding the force-unwrap is one way assuming that
nilonly appears for file we wouldn't want to lint anyway. But what would be the result ofurl.filepaththen? Or if we find out what fixed the issue in Foundation, maybe we can take over the fix temporarily ...@compnerd: I'm keen to hear your opinion and interpretation.
compnerd commentedon Jan 14, 2026
That is pretty terrible, but I can understand why -
:is restricted on Windows file systems (it is the ADS separator and the drive separator). The file would not be writable in the first place and would most likely trigger an abnormal exit somewhere. This really feels like a client side issue as they should avoid using:in the filename. I think that your analysis is correct that we would fail to lint this in the first place. The only thing that I can think of is perhaps we should do something like this instead:to improve the diagnostics.
SimplyDanny commentedon Jan 14, 2026
Better reporting instead of crashing will be done with #6435. There's nothing more we can do. The issue can easily be avoided by excluding folders with these problematic files (which is a good idea anyway to speed up linting).
@liliomk-supercharge: Thank you for the analysis, logs and the example project!
@compnerd: Thank you for your fast responses and valuable insights!
SimplyDanny commentedon Jan 15, 2026
Good news: The "URL over string paths" PR #6408 makes it work for all macOS versions again.