-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Replaced FileNotFoundException with log instead (#199) #200
base: develop
Are you sure you want to change the base?
Conversation
@@ -42,7 +47,7 @@ public IFileInfo GetRequiredFileInfo(string filePath) | |||
|
|||
if (!fileInfo.Exists) | |||
{ | |||
throw new FileNotFoundException($"No such file exists {fileInfo.PhysicalPath ?? fileInfo.Name} (mapped from {filePath})", fileInfo.PhysicalPath ?? fileInfo.Name); |
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 think this should be handled differently, now fileInfo is returned even when its useless (also in MemoryCacheFileSystem).
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.
Which is as intended, as other parts of the logic will check for .Exists
, which is precisely what a FileInfo is for (a cheap wrapper to tell you if a file exists before attempting to open it). You also annotated the old code :)
Returning null here would mean a lot more code has to be touched and double-checked.
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.
Which is as intended, as other parts of the logic will check for
.Exists
, which is precisely what a FileInfo is for (a cheap wrapper to tell you if a file exists before attempting to open it). You also annotated the old code :)Returning null here would mean a lot more code has to be touched and double-checked.
It's already documented that GetRequiredFileInfo throws:
/// Throws an exception if the file doesn't exist |
So this would be breaking anyway.
Not all other paths check if the file exists (only SmidgeController does):
var sourceFile = new Lazy<IFileInfo>(() => _fileSystem.GetRequiredFileInfo(file), LazyThreadSafetyMode.None); |
var filePath = _fileSystem.GetRequiredFileInfo(path); |
This would also apply to other people using the library, now it doesn't throw anymore and you need to handle it differently.
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.
Remark about breaking change is fair, the other ones are easily "fixed" by reintroducing the exception right after retrieving the IFileInfo. I will push that in a second.
The two locations you pointed out are literally the only 2 places where something is done with GetRequiredFileInfo
. They are also only called in very specific situations: @import
in CSS and during bundle creation, both of which cannot be directly manipulated by malicious users (only malicious developers :P). That said, bundle creation would also need some love as I pointed out, but for another PR.
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.
Remark about breaking change is fair, the other ones are easily "fixed" by reintroducing the exception right after retrieving the IFileInfo.
Not everyone uses Smidge as-is, some have custom implementations around it. I don't mind fixing this at all, but let's try to get consistent behavior
I think it's fine not to throw anymore; then PreProcessManager can bail out, and CssImportProcessor can continue with the others.
Alternatively, SmidgeController could swallow the exception. This would be the least breaking change.
@Shazwazza what would you prefer?
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, i don't think we should change the behavior of this method since the meaning is in the name 'GetRequired...' ... which indicates that it will throw.
One way to be less breaking would be to have an optional overload of this like bool throwIfNotFound = true
It is a binary breaking change, but all folks nowadays build their projects before deploying so I don't think it would cause any issues.
Else I'm fine with try/catch/swallow where necessary
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.
@LennardF1989 just wanted to ping on this one?
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.
Honestly, I forgot that I did this xD I'll put it back on my list.
Fixes #199.
AddSmidgeInMemory
and manipulating some of the generated/sc
-URLs:Upon testing, it looks like
/sb
-URLs could use a similar treatment as it will throw an exception when the bundle-key or version is invalid, but I'd say that's something for another PR.EDIT: PS. I removed a myget-reference that is no longer valid and prevents restoring packages.