Skip to content

Commit

Permalink
Improve error logging of the exception.
Browse files Browse the repository at this point in the history
The URI is being passed to avoid needing to get the URI from the Resource.
Getting the URI from the Resource would introduce another exception that needs to be handled.
  • Loading branch information
kaladay committed Apr 18, 2022
1 parent f6dff81 commit 84dd95a
Showing 1 changed file with 9 additions and 5 deletions.
Expand Up @@ -74,19 +74,19 @@ private Optional<File> getScssFile(String url) {

Resource resource = resourcePatternResolver.getResource(url);

if (!resourceExists(resource)) {
if (!resourceExists(resource, url)) {
url = "classpath:" + url;
resource = resourcePatternResolver.getResource(url);
}

if (!resourceExists(resource)) {
if (!resourceExists(resource, url)) {
final int lastSlash = url.lastIndexOf('/') + 1;
String cleanUrl = url.substring(0, lastSlash);
cleanUrl = cleanUrl + "_" + url.substring(lastSlash, url.length());
resource = resourcePatternResolver.getResource(cleanUrl);
}

if (resourceExists(resource) && resource.isReadable()) {
if (resourceExists(resource, url) && resource.isReadable()) {
try {
if (resource.getURI().getScheme().equals("jar")) {
File tempFile = File.createTempFile("wro", ".tmp");
Expand Down Expand Up @@ -123,14 +123,18 @@ public InputStream locate(final String uri) throws IOException {
* The stack trace is suppressed unless debug is enabled.
*
* @param resource The resource to check.
* @param uri The URI represented by the resource (used for error logging).
* @return TRUE if resource exists, FALSE otherwise.
*/
private boolean resourceExists(Resource resource) {
private boolean resourceExists(Resource resource, String uri) {
try {
return resource.exists();
} catch (IllegalArgumentException e) {
String message = "Existence check failed for URI: " + uri;
if (LOG.isDebugEnabled()) {
e.printStackTrace();
LOG.error(message, e);
} else {
LOG.warn(message);
}
}

Expand Down

0 comments on commit 84dd95a

Please sign in to comment.