Closed eldontc closed 4 years ago
+1 for fixing this issue. Just spent a lot of time to find out that my yml properties file had a duplicate key. The error message from the spring cloud server has no useful information.
This burned me for a bit as well so I'd be interested in helping out with this. Is there any reason not to wrap the loader.load
bit in ConfigFileApplicationListener::592
in some custom exception like FailedToLoadResourceException
that could be caught in a controller advice?
@nhomble if you would like to help, submit a PR with your proposed solution and we can review it
ConfigFileApplicationListener
is part of spring boot, not spring cloud.
Oh good catch I was lazily looking at the stacktrace from a repro I got on my branch.
I'll happily follow up with a proposal!
https://github.com/nhomble/spring-cloud-config/tree/feature/gh-1283
Sorry for the initial suggestion, as @spencergibb pointed out, that bit comes from spring boot when we load a spring application in NativeEnvironmentRepository
. My idea is still the same though. When we invoke the builder we get an IllegalStateException from spring boot with the actual underlying cause (in my case I forced a yml dupe key exception). I wrapped a separate custom exception for bad contexts to be caught in a resource exception handler. In case the exception message could have sensitive info, I only report the canonical name of the root exception and our custom message which I hope suffices.
Those who are trying to use local files, make sure your folder is git initiated.
Ex: In Windows, folder "application-config" is configured for git (i.e. > git init, git add *.properties, git commit)
spring.cloud.config.server.git.uri=file:///C:/configserver/application-config
I've experienced a problem with spring cloud config client when unfortunately pushed an invalid yaml file to my git repository. The message that I've got is:
o.s.c.c.c.ConfigServicePropertySourceLocator - Fetching config from server at: http://my-config-server:8888 ERROR [] o.s.boot.SpringApplication - Application startup failedjava.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
With this message, I was investigating my problem in the wrong way. Actually, the problem was not the absence of PropertySource. I spent my time to realize that the real problem was an invalid yaml file with the wrong syntax.
I am using the spring-cloud-config-client:2.0.0.M9
Enhancement I suggest that the above error message could be more specific, like "Could not load a file on config repository. The file name-of-file is invalid". When name-of-file could be the equivalent to spring.application.name + profile.
A debug flag on configurantion inside the bootstrap.properties could be valueable. Something like:
With default to false
Whe debug is flagged to true, some precious messages could be printed on console, like the files that client is trying to get,