Skip to content

Exception is thrown when component failed to register #1361

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

Merged
merged 4 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
ci.register();
} catch (Throwable t) {
SofaLogger.error(ErrorCode.convert("01-03003", ci.getName()), t);
return null;
throw new ServiceRuntimeException(ErrorCode.convert("01-03003", ci.getName()));
}

SofaLogger.info("Registering component: {}", ci.getName());
Expand All @@ -189,6 +189,7 @@
} catch (Throwable t) {
ci.exception(new Exception(t));
SofaLogger.error(ErrorCode.convert("01-03004", ci.getName()), t);
throw new ServiceRuntimeException(ErrorCode.convert("01-03004", ci.getName()));

Check warning on line 192 in sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/ComponentManagerImpl.java#L192

Added line #L192 was not covered by tests
}

return ci;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand Down Expand Up @@ -68,7 +69,8 @@ public void testSofaServiceClassNotAssignableFromInterfaceType() throws IOExcept
TestSofaServiceNotAssignableFromInterfaceTypeConfiguration.class);
springApplication.setWebApplicationType(WebApplicationType.NONE);
springApplication.setDefaultProperties(properties);
springApplication.run();

Assert.assertThrows(BeanCreationException.class, springApplication::run);

String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOExcep
serviceParam.setInstance(new Object());
serviceParam.setInterfaceType(SampleService.class);
serviceParam.addBindingParam(jvmBindingParam);
serviceClient.service(serviceParam);
Assert.assertThrows(Exception.class, ()-> serviceClient.service(serviceParam));

String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void testServiceBinding() throws IOException {
SofaBindingTestIsNotAssignableFromInterfaceTypeConfiguration.class);
springApplication.setWebApplicationType(WebApplicationType.NONE);
springApplication.setDefaultProperties(properties);
springApplication.run();

Assert.assertThrows(Exception.class, springApplication::run);

String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert
Expand Down