Skip to content
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

Rewrote the "child binding already set" error message for better clarity. #1846

Merged
merged 1 commit into from
Nov 21, 2024
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 @@ -21,8 +21,10 @@ final class ChildBindingAlreadySetError extends InternalErrorDetail<ChildBinding
super(
ErrorId.CHILD_BINDING_ALREADY_SET,
String.format(
"Unable to create binding for %s because it was already configured on one or more"
+ " child injectors or private modules.",
"A binding for %s already exists in one or more child injectors or private modules."
+ " Bindings from children can only be used by a parent if the child was a"
+ " PrivateModule and the binding was exposed. Parent injectors cannot create"
+ " bindings that already exist in a child.",
Messages.convert(key)),
sources,
null);
Expand Down
8 changes: 5 additions & 3 deletions core/test/com/google/inject/JitBindingsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ private String jitInParentFailed(TypeLiteral<?> clazz) {
}

private String inChildMessage(Class<?> clazz) {
return "Unable to create binding for "
+ "JitBindingsTest$"
return "A binding for JitBindingsTest$"
+ clazz.getSimpleName()
+ " because it was already configured on one or more child injectors or private modules";
+ " already exists in one or more child"
+ " injectors or private modules. Bindings from children can only be used by a parent if"
+ " the child was a PrivateModule and the binding was exposed. Parent injectors cannot"
+ " create bindings that already exist in a child.";
}

public void testLinkedBindingWorks() {
Expand Down
10 changes: 7 additions & 3 deletions core/test/com/google/inject/ParentInjectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** @author jessewilson@google.com (Jesse Wilson) */
/**
* @author jessewilson@google.com (Jesse Wilson)
*/
@RunWith(JUnit4.class)
public class ParentInjectorTest {

Expand Down Expand Up @@ -70,8 +72,10 @@ public void testParentJitBindingWontClobberChildBinding() {
} catch (ConfigurationException e) {
assertContains(
e.getMessage(),
"Unable to create binding for ParentInjectorTest$A because it was already configured on"
+ " one or more child injectors or private modules.",
"A binding for ParentInjectorTest$A already exists in one or more child injectors or"
+ " private modules. Bindings from children can only be used by a parent if the child"
+ " was a PrivateModule and the binding was exposed. Parent injectors cannot create"
+ " bindings that already exist in a child.",
"ParentInjectorTest$9.configure");
}
}
Expand Down
22 changes: 15 additions & 7 deletions core/test/com/google/inject/PrivateModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
import java.util.List;
import junit.framework.TestCase;

/** @author jessewilson@google.com (Jesse Wilson) */
/**
* @author jessewilson@google.com (Jesse Wilson)
*/
public class PrivateModuleTest extends TestCase {

public void testBasicUsage() {
Expand Down Expand Up @@ -589,8 +591,10 @@ public void testParentBindsSomethingInPrivate() {
assertEquals(1, expected.getErrorMessages().size());
assertContains(
expected.toString(),
"Unable to create binding for List<String> ",
"because it was already configured on one or more child injectors or private modules.",
"A binding for List<String> already exists in one or more child injectors",
" or private modules. Bindings from children can only be used by a parent if the child",
" was a PrivateModule and the binding was exposed. Parent injectors cannot create",
" bindings that already exist in a child.",
"1 : PrivateModuleTest$FailingPrivateModule.configure",
"PrivateModuleTest$FailingModule -> PrivateModuleTest$ManyPrivateModules ->"
+ " PrivateModuleTest$FailingPrivateModule",
Expand All @@ -610,8 +614,10 @@ public void testParentBindingToPrivateLinkedJitBinding() {
assertEquals(1, expected.getErrorMessages().size());
assertContains(
expected.toString(),
"Unable to create binding for List<String> because it was already configured on one or"
+ " more child injectors or private modules",
"A binding for List<String> already exists in one or more child injectors",
" or private modules. Bindings from children can only be used by a parent if the child",
" was a PrivateModule and the binding was exposed. Parent injectors cannot create",
" bindings that already exist in a child.",
"1 : PrivateModuleTest$FailingPrivateModule.configure",
"PrivateModuleTest$ManyPrivateModules -> PrivateModuleTest$FailingPrivateModule",
"2 : PrivateModuleTest$SecondFailingPrivateModule.configure",
Expand All @@ -628,8 +634,10 @@ public void testParentBindingToPrivateJitBinding() {
assertEquals(1, expected.getErrorMessages().size());
assertContains(
expected.toString(),
"Unable to create binding for PrivateModuleTest$PrivateFoo because it was already"
+ " configured on one or more child injectors or private modules.",
"A binding for PrivateModuleTest$PrivateFoo already exists in one or more child",
" injectors or private modules. Bindings from children can only be used by a parent if",
" the child was a PrivateModule and the binding was exposed. Parent injectors cannot",
" create bindings that already exist in a child.",
"as a just-in-time binding");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Guice configuration errors:

1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$DependsOnFoo because it was already configured on one or more child injectors or private modules.
1) [Guice/ChildBindingAlreadySet]: A binding for ChildBindingAlreadySetErrorTest$DependsOnFoo already exists in one or more child injectors or private modules. Bindings from children can only be used by a parent if the child was a PrivateModule and the binding was exposed. Parent injectors cannot create bindings that already exist in a child.

Bound at:
1 : ChildBindingAlreadySetErrorTest$ChildModule4.configure(ChildBindingAlreadySetErrorTest.java:105)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Guice configuration errors:

1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
1) [Guice/ChildBindingAlreadySet]: A binding for ChildBindingAlreadySetErrorTest$Foo already exists in one or more child injectors or private modules. Bindings from children can only be used by a parent if the child was a PrivateModule and the binding was exposed. Parent injectors cannot create bindings that already exist in a child.

Bound at:
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Guice configuration errors:

1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
1) [Guice/ChildBindingAlreadySet]: A binding for ChildBindingAlreadySetErrorTest$Foo already exists in one or more child injectors or private modules. Bindings from children can only be used by a parent if the child was a PrivateModule and the binding was exposed. Parent injectors cannot create bindings that already exist in a child.

Bound at:
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Unable to create injector, see the following errors:

1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
1) [Guice/ChildBindingAlreadySet]: A binding for ChildBindingAlreadySetErrorTest$Foo already exists in one or more child injectors or private modules. Bindings from children can only be used by a parent if the child was a PrivateModule and the binding was exposed. Parent injectors cannot create bindings that already exist in a child.

Bound at:
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)
Expand Down
Loading