Is your feature request related to a problem? Please describe. Hi! I'm newbie on spring config and frustrated by the 404 error on my config server Spring Cloud Config suggestion on Exception Handling in MultipleJGitEnvironmentRepository

the error log is like no such label master

I google the error and the answer is like add default-label @ application.properties

spring.cloud.config.server.git.default-label= main

but it did not solve the problem. Now I Found That default label is now main @ defulat and the tryMaster feature was added due to maintain compatibility related commit


above was my story of how i get to this suggestion.

I hope the method MultipleJGitEnvironmentRepository.findOne provide a little more kind log or exception handling in blow lines

line 175

catch (Exception e) {
    if (MultipleJGitEnvironmentProperties.MAIN_LABEL.equals(label) && isTryMasterBranch()) {
        candidate = getRepository(this, application, profile, MultipleJGitEnvironmentProperties.MASTER_LABEL);
        return findOneFromCandidate(candidate, application, profile,
                MultipleJGitEnvironmentProperties.MASTER_LABEL, includeOrigin);
    }
    throw e;
}

if the error is catched and then it try again on master branch

if another error is throw while try on master branch. it just eat the original exception which is thrown by first try (main branch) !!!

Describe the solution you'd like A clear and concise description of what you want to happen. I want to add simple log for original exception.

Additional context the log i expected Spring Cloud Config suggestion on Exception Handling in MultipleJGitEnvironmentRepository

i solve my problem and got to know actual exception by set

spring.cloud.config.server.git.try-master-branch: false

the log i got Spring Cloud Config suggestion on Exception Handling in MultipleJGitEnvironmentRepository

Comment From: woshikid

What about a suppressed exception?

catch (Exception e) {
    if (MultipleJGitEnvironmentProperties.MAIN_LABEL.equals(label) && isTryMasterBranch()) {
        candidate = getRepository(this, application, profile, MultipleJGitEnvironmentProperties.MASTER_LABEL);
        try {
            return findOneFromCandidate(candidate, application, profile, MultipleJGitEnvironmentProperties.MASTER_LABEL, includeOrigin);
        } catch (Exception e1) {
            e1.addSuppressed(e); // add the original exception as suppressed
            throw e1;
        }
    }
    throw e;
}

Comment From: woshikid

or we can just throw the original exception, ignore the exception caused by Try Master Branch feature.

Comment From: ndy2

Both ideas look good!! I hope we can notice the original Exception when it is thrown

Comment From: woshikid

I will make a PR with Suppressed Exception solution.

Comment From: ndy2

Can i make a PR with your idea? T.T

I will be really appreciate and honor to contribute this project

Comment From: woshikid

OK, you can take it.

Comment From: ndy2

Thanks a lot!