Skip to content

KarmanProviders throws improper exception $className property not found #1

@neilabdev

Description

@neilabdev

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
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions