Skip to content

Commit bf43b4f

Browse files
samebGuice Team
authored andcommitted
Rewrote the "child binding already set" error message for better clarity.
PiperOrigin-RevId: 698811431
1 parent 21381e3 commit bf43b4f

8 files changed

+35
-19
lines changed

core/src/com/google/inject/internal/ChildBindingAlreadySetError.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ final class ChildBindingAlreadySetError extends InternalErrorDetail<ChildBinding
2121
super(
2222
ErrorId.CHILD_BINDING_ALREADY_SET,
2323
String.format(
24-
"Unable to create binding for %s because it was already configured on one or more"
25-
+ " child injectors or private modules.",
24+
"A binding for %s already exists in one or more child injectors or private modules."
25+
+ " Bindings from children can only be used by a parent if the child was a"
26+
+ " PrivateModule and the binding was exposed. Parent injectors cannot create"
27+
+ " bindings that already exist in a child.",
2628
Messages.convert(key)),
2729
sources,
2830
null);

core/test/com/google/inject/JitBindingsTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ private String jitInParentFailed(TypeLiteral<?> clazz) {
5353
}
5454

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

6264
public void testLinkedBindingWorks() {

core/test/com/google/inject/ParentInjectorTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
import org.junit.runner.RunWith;
4242
import org.junit.runners.JUnit4;
4343

44-
/** @author [email protected] (Jesse Wilson) */
44+
/**
45+
* @author [email protected] (Jesse Wilson)
46+
*/
4547
@RunWith(JUnit4.class)
4648
public class ParentInjectorTest {
4749

@@ -70,8 +72,10 @@ public void testParentJitBindingWontClobberChildBinding() {
7072
} catch (ConfigurationException e) {
7173
assertContains(
7274
e.getMessage(),
73-
"Unable to create binding for ParentInjectorTest$A because it was already configured on"
74-
+ " one or more child injectors or private modules.",
75+
"A binding for ParentInjectorTest$A already exists in one or more child injectors or"
76+
+ " private modules. Bindings from children can only be used by a parent if the child"
77+
+ " was a PrivateModule and the binding was exposed. Parent injectors cannot create"
78+
+ " bindings that already exist in a child.",
7579
"ParentInjectorTest$9.configure");
7680
}
7781
}

core/test/com/google/inject/PrivateModuleTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.util.List;
3333
import junit.framework.TestCase;
3434

35-
/** @author [email protected] (Jesse Wilson) */
35+
/**
36+
* @author [email protected] (Jesse Wilson)
37+
*/
3638
public class PrivateModuleTest extends TestCase {
3739

3840
public void testBasicUsage() {
@@ -589,8 +591,10 @@ public void testParentBindsSomethingInPrivate() {
589591
assertEquals(1, expected.getErrorMessages().size());
590592
assertContains(
591593
expected.toString(),
592-
"Unable to create binding for List<String> ",
593-
"because it was already configured on one or more child injectors or private modules.",
594+
"A binding for List<String> already exists in one or more child injectors",
595+
" or private modules. Bindings from children can only be used by a parent if the child",
596+
" was a PrivateModule and the binding was exposed. Parent injectors cannot create",
597+
" bindings that already exist in a child.",
594598
"1 : PrivateModuleTest$FailingPrivateModule.configure",
595599
"PrivateModuleTest$FailingModule -> PrivateModuleTest$ManyPrivateModules ->"
596600
+ " PrivateModuleTest$FailingPrivateModule",
@@ -610,8 +614,10 @@ public void testParentBindingToPrivateLinkedJitBinding() {
610614
assertEquals(1, expected.getErrorMessages().size());
611615
assertContains(
612616
expected.toString(),
613-
"Unable to create binding for List<String> because it was already configured on one or"
614-
+ " more child injectors or private modules",
617+
"A binding for List<String> already exists in one or more child injectors",
618+
" or private modules. Bindings from children can only be used by a parent if the child",
619+
" was a PrivateModule and the binding was exposed. Parent injectors cannot create",
620+
" bindings that already exist in a child.",
615621
"1 : PrivateModuleTest$FailingPrivateModule.configure",
616622
"PrivateModuleTest$ManyPrivateModules -> PrivateModuleTest$FailingPrivateModule",
617623
"2 : PrivateModuleTest$SecondFailingPrivateModule.configure",
@@ -628,8 +634,10 @@ public void testParentBindingToPrivateJitBinding() {
628634
assertEquals(1, expected.getErrorMessages().size());
629635
assertContains(
630636
expected.toString(),
631-
"Unable to create binding for PrivateModuleTest$PrivateFoo because it was already"
632-
+ " configured on one or more child injectors or private modules.",
637+
"A binding for PrivateModuleTest$PrivateFoo already exists in one or more child",
638+
" injectors or private modules. Bindings from children can only be used by a parent if",
639+
" the child was a PrivateModule and the binding was exposed. Parent injectors cannot",
640+
" create bindings that already exist in a child.",
633641
"as a just-in-time binding");
634642
}
635643
}

core/test/com/google/inject/errors/testdata/child_binding_already_set_by_just_in_time_binding.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Guice configuration errors:
22

3-
1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$DependsOnFoo because it was already configured on one or more child injectors or private modules.
3+
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.
44

55
Bound at:
66
1 : ChildBindingAlreadySetErrorTest$ChildModule4.configure(ChildBindingAlreadySetErrorTest.java:105)

core/test/com/google/inject/errors/testdata/child_binding_already_set_error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Guice configuration errors:
22

3-
1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
3+
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.
44

55
Bound at:
66
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)

core/test/com/google/inject/errors/testdata/child_binding_already_set_multiple_times_error.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Guice configuration errors:
22

3-
1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
3+
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.
44

55
Bound at:
66
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)

core/test/com/google/inject/errors/testdata/multiple_child_binding_already_set_errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Unable to create injector, see the following errors:
22

3-
1) [Guice/ChildBindingAlreadySet]: Unable to create binding for ChildBindingAlreadySetErrorTest$Foo because it was already configured on one or more child injectors or private modules.
3+
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.
44

55
Bound at:
66
1 : ChildBindingAlreadySetErrorTest$ChildModule.configure(ChildBindingAlreadySetErrorTest.java:34)

0 commit comments

Comments
 (0)