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

Error handling when loading assemblies from an external folder #866

Merged

Conversation

filipw
Copy link
Member

@filipw filipw commented May 18, 2017

Follow up to #848

Added try/catch to the directory enumeration inside AssemblyLoader. It can throw due to a number of problems - directory not found, path too long, lack of permissions etc.
We should gracefully exit with no assemblies loaded and not crash OmniSharp.

@filipw filipw force-pushed the bugfix/extensions-non-existing-path branch from ac8a22f to 0cbaf04 Compare May 18, 2017 19:31
}
catch (Exception ex)
{
_logger.LogError(ex, $"An error occurred when attempting to access '{folderPath}'.");
Copy link
Contributor

Choose a reason for hiding this comment

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

This message could be wrong if something else fails. I can't see what would fail though. 😄

Is there any reason not to check Directory.Exists(folderPath)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had it in the initial commit (76906f9) but then I decided to go for try/catch instead as that would cover a lot more potential edge cases i.e. PathTooLongException, SecurityException, UnauthorizedAccessException, IOException rather than just DirectoryNotFoundException

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

if (assembly != null)
var assemblies = new List<Assembly>();

foreach (var filePath in Directory.EnumerateFiles(folderPath, "*.dll"))
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe this should be SearchOption.AllDirectories?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather that be passed in. Could be surprising behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah maybe it's too much at all to even think about it. let's keep it simple for now and when/if more advanced use cases come up then we can decide what to do (i.e. allow this setting to be bound from config too and so on)

@DustinCampbell DustinCampbell merged commit 81c790b into OmniSharp:dev May 25, 2017
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