Replaced FileNotFoundException with log instead (#199) - #200
Replaced FileNotFoundException with log instead (#199)#200LennardF1989 wants to merge 2 commits into
Conversation
|
|
||
| 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.
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.
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.
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:
So this would be breaking anyway.
Not all other paths check if the file exists (only SmidgeController does):
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.
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.
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.
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.
Honestly, I forgot that I did this xD I'll put it back on my list.
Fixes #199.
AddSmidgeInMemoryand 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.