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

KarmanProviders throws improper exception $className property not found #1

Open
neilabdev opened this issue Aug 16, 2015 · 0 comments

Comments

@neilabdev
Copy link

If a provider can't be found, the error message received is incorrect, because there is an exception thrown during the error logging processes. Solution is to move the $className variable to a scope that can been seen in exception, such as before the try. See :todo below:

static synchronized Map<String,Class<StorageProviderInterface>> loadProviders(ClassLoader classLoader = Thread.currentThread().contextClassLoader) {

        if(providers == null) {
            def resources = classLoader.getResources(FACTORIES_RESOURCE_LOCATION)
            providers = [:]

            resources.each { URL res ->
                Properties providerProperties = new Properties()
                providerProperties.load(res.openStream())

                providerProperties.keySet().each { providerName ->
                    try {
                        String className = providerProperties.getProperty(providerName)
                        def cls = classLoader.loadClass(className)
                        if(StorageProviderInterface.isAssignableFrom(cls)) {
                            if(!providers[providerName]) {
                                providers[providerName] = cls
                            }
                        } else {
                            log.warn("Karman Storage Provider $className not registered because it does not implement the StorageProviderInterface")        
                        }
                    } catch(Throwable e) {
   // TODO: make $className in higher scope so when provider can't be found, real error will log. Otherwise it will complain that $className can't be found.
                        log.error("Error Loading Karman Storage Provider $className: $e.message",e)
                    } 
                }
            }
        }
        return providers
    }
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

No branches or pull requests

1 participant