spring-cloud / spring-cloud/spring-cloud-config
Throw Exception When A Repo In A Multi Git Configuration Fails - Do Not Fallback To Default Repo
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 1.3k
- Avg merge
- 2d 59m
- Merged PRs (30d)
- 16
Description
Describe the bug
When on a multiple repository setup where one of the alternate repository contains unsupported legacy spring configuration, the exception NoSuchLabelException is thrown instead of the expected InvalidConfigDataPropertyException.
Spring Boot version : 3.0.5
Spring Cloud version : 2022.0.2
Sample
Repository setup :
spring:
cloud:
config:
server:
git:
clone-on-start: true
default-label: master
uri: ${application.repositories.default}
search-paths: ${application.search-paths.default}
repos:
staging:
pattern: "*/*staging*"
uri: ${application.repositories.alternate}
search-paths: ${application.search-paths.default}
invalid application.yml within the alternate repository :
---
spring:
profiles: profile1
datasource:
username: john
actual error message when request matches the alternate "staging" repository :
2023.05.01 09:29:28.988 | [http-nio-8080-exec-1] | ERROR | [dispatcherServlet] | | | CORRELATION_ID=<nocor_id> | Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.cloud.config.server.environment.NoSuchLabelException: No such label: 1.0.0] with root cause
org.eclipse.jgit.api.errors.RefNotFoundException: Ref 1.0.0 cannot be resolved
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:224)
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.checkout(JGitEnvironmentRepository.java:467)
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.refresh(JGitEnvironmentRepository.java:306)
at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.getLocations(JGitEnvironmentRepository.java:262)
at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.getLocations(MultipleJGitEnvironmentRepository.java:144)
at org.springframework.cloud.config.server.environment.SearchPathCompositeEnvironmentRepository.addForSearchPathLocators(SearchPathCompositeEnvironmentRepository.java:72)
at org.springframework.cloud.config.server.environment.SearchPathCompositeEnvironmentRepository.getLocations(SearchPathCompositeEnvironmentRepository.java:55)
at org.springframework.cloud.config.server.resource.GenericResourceRepository.findOne(GenericResourceRepository.java:67)
expected error message, as thrown when coming from the default repo :
2023.05.01 09:27:38.796 | [http-nio-8080-exec-6] | ERROR | [dispatcherServlet] | | | CORRELATION_ID=<nocor_id> | Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.cloud.config.server.environment.FailedToConstructEnvironmentException: Could not construct context for config=myapp profile=staging label= includeOrigin=false; nested exception is org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles' imported from location 'file [C:\Users\naskalit\AppData\Local\Temp\config-repo-2369028666792197659\staging\myapp\application.yml]' is invalid and should be replaced with 'spring.config.activate.on-profile' [origin: URL [file:/C:/Users/naskalit/AppData/Local/Temp/config-repo-2369028666792197659/staging/myapp/application.yml] - 10:13]] with root cause
org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles' imported from location 'file [C:\Users\naskalit\AppData\Local\Temp\config-repo-2369028666792197659\staging\myapp\application.yml]' is invalid and should be replaced with 'spring.config.activate.on-profile' [origin: URL [file:/C:/Users/naskalit/AppData/Local/Temp/config-repo-2369028666792197659/staging/myapp/application.yml] - 10:13]
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.lambda$throwIfPropertyFound$0(InvalidConfigDataPropertyException.java:113)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
at org.springframework.boot.context.config.InvalidConfigDataPropertyException.throwIfPropertyFound(InvalidConfigDataPropertyException.java:109)
at org.springframework.boot.context.config.ConfigDataEnvironment.checkForInvalidProperties(ConfigDataEnvironment.java:364)
at org.springframework.boot.context.config.ConfigDataEnvironment.applyToEnvironment(ConfigDataEnvironment.java:328)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:235)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:96)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.applyTo(ConfigDataEnvironmentPostProcessor.java:169)
at org.springframework.cloud.config.server.environment.NativeEnvironmentRepository.findOne(NativeEnvironmentRepository.java:145)
at org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository.findOne(AbstractScmEnvironmentRepository.java:64)
at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.findOneFromCandidate(MultipleJGitEnvironmentRepository.java:195)
at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.findOne(MultipleJGitEnvironmentRepository.java:178)
at org.springframework.cloud.config.server.environment.ObservationEnvironmentRepositoryWrapper.lambda$findOne$3(ObservationEnvironmentRepositoryWrapper.java:75)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing MultipleJGitEnvironmentRepository.findOne and findOneFromCandidate, then follow JGitEnvironmentRepository.refresh and checkout for the alternate repository path. Compare how the default repository propagates InvalidConfigDataPropertyException with how the alternate path produces NoSuchLabelException. Done means a matching alternate repository reports the configuration error instead of falling back to the default repository or reporting a missing label.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, java, spring, spring-boot
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100