Fix(fuzzy-finder) fs.lstatSync throws Exception if not a file or dir #944
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Identify the Bug
While trying to fix a self-hosted teletype version, I noticed the fuzzy-finder is broken with teletype and it is because of this:
If you try to use the fuzzy-finder while connected via teletype, it fails with an exception.
This is caused by a check if the uri is a directory. The used
fs.lstatSync
will throw if given path is not found.Previously it used a fs-plus method, which did not throw.
Because it throws, the else branch is never reached for the teletype URIs.
Description of the Change
wrap
fs.lstatSync
in a try-catch blockAlternate Designs
I would love to do something like this
unfortunately
throwIfNoEntry
is only available in newer versions offs
.Alternative 2: Could revert to fs-plus, the old code did not throw
Alternative 3: It could be sufficient to explicitly check if it is a teletype URI, I do not know if there could be other types of URI.
Teletype URIs all start with
atom://teletype/
Possible Drawbacks
Code could be harder to read.
Verification Process
I used the fuzzy-finder, did not crash. Also did not crash with teletype.
Release Notes
N/A