Skip to content

Commit ddd7d70

Browse files
committed
Error out on invalid rc commands
1 parent 3e4d9fe commit ddd7d70

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,13 @@ static ListMultimap<String, RcChunkOfArgs> structureRcOptionsAndConfigs(
629629
if (!validCommands.contains(command)
630630
&& !command.equals(ALWAYS_PSEUDO_COMMAND)
631631
&& !command.equals(COMMON_PSEUDO_COMMAND)) {
632-
eventHandler.handle(
633-
Event.warn(
634-
"while reading option defaults file '"
635-
+ rcFile
636-
+ "':\n"
637-
+ " invalid command name '"
638-
+ override.command
639-
+ "'."));
640-
continue;
632+
throw new OptionsParsingException(
633+
"while reading option defaults file '"
634+
+ rcFile
635+
+ "':\n"
636+
+ " invalid command name '"
637+
+ override.command
638+
+ "'.");
641639
}
642640

643641
// We've moved on to another rc file "chunk," store the accumulated args from the last one.

src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,20 @@ public void testStructureRcOptionsAndConfigs_configOnly() throws Exception {
152152

153153
@Test
154154
public void testStructureRcOptionsAndConfigs_invalidCommand() throws Exception {
155-
BlazeOptionHandler.structureRcOptionsAndConfigs(
156-
eventHandler,
157-
Arrays.asList("rc1", "rc2"),
158-
Arrays.asList(new ClientOptions.OptionOverride(0, "c1", "a")),
159-
ImmutableSet.of("build"));
160-
assertThat(eventHandler.getEvents())
161-
.contains(
162-
Event.warn("while reading option defaults file 'rc1':\n invalid command name 'c1'."));
155+
OptionsParsingException e =
156+
assertThrows(
157+
OptionsParsingException.class,
158+
() ->
159+
BlazeOptionHandler.structureRcOptionsAndConfigs(
160+
eventHandler,
161+
Arrays.asList("rc1", "rc2"),
162+
Arrays.asList(new ClientOptions.OptionOverride(0, "c1", "a")),
163+
ImmutableSet.of("build")));
164+
assertThat(parser.getResidue()).isEmpty();
165+
assertThat(optionHandler.getRcfileNotes()).isEmpty();
166+
assertThat(e)
167+
.hasMessageThat()
168+
.contains("while reading option defaults file 'rc1':\n invalid command name 'c1'.");
163169
}
164170

165171
@Test

0 commit comments

Comments
 (0)