-
Notifications
You must be signed in to change notification settings - Fork 420
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
Error handling when loading assemblies from an external folder #866
Conversation
ac8a22f
to
0cbaf04
Compare
} | ||
catch (Exception ex) | ||
{ | ||
_logger.LogError(ex, $"An error occurred when attempting to access '{folderPath}'."); |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
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.