Skip to content

Commit 34059ae

Browse files
authored
Merge pull request #289 from getappmap/fix/config-packages-key-missing-value
fix: crash due to config packages key with missing value
2 parents 011a645 + 26714d8 commit 34059ae

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

agent/src/main/java/com/appland/appmap/config/AppMapConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ static AppMapConfig load(Path configFile, boolean mustExist) {
131131
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
132132
try {
133133
singleton = mapper.readValue(inputStream, AppMapConfig.class);
134+
if (singleton.packages == null) {
135+
logger.error("AppMap: missing value for the 'packages' entry in appmap.yml");
136+
return null;
137+
}
134138
} catch (IOException e) {
135139
logger.error("AppMap: encountered syntax error in appmap.yml {}", e.getMessage());
136-
System.exit(1);
140+
return null;
137141
}
138142
singleton.configFile = configFile;
139143
logger.debug("config: {}", singleton);

agent/src/test/java/com/appland/appmap/config/AppMapConfigTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ public void hasAppmapDir() throws Exception {
100100
AppMapConfig.load(configFile, true);
101101
assertEquals("/appmap", AppMapConfig.get().getAppmapDir());
102102
}
103+
104+
@Test
105+
public void loadPackagesKeyWithMissingValue() throws Exception {
106+
Path configFile = tmpdir.resolve("appmap.yml");
107+
final String contents = "name: test\npackages:\npath: xyz";
108+
Files.write(configFile, contents.getBytes());
109+
String actualErr = tapSystemErr(() -> AppMapConfig.load(configFile, false));
110+
assertTrue(actualErr.contains("AppMap: missing value for the 'packages'"));
111+
}
112+
113+
@Test
114+
public void loadPackagesKeyWithScalarValue() throws Exception {
115+
Path configFile = Files.createTempFile("appmap", ".yml");
116+
final String contents = "name:q test\npackages: abc\n";
117+
Files.write(configFile, contents.getBytes());
118+
String actualErr = tapSystemErr(() -> AppMapConfig.load(configFile, false));
119+
assertTrue(actualErr.contains("AppMap: encountered syntax error in appmap.yml"));
120+
}
103121
}
104122

105123

agent/test/intellij/intellij.bats

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ setup() {
3131
}
3232

3333
@test 'it works' {
34-
# TODO: remove this ideVersion pin
35-
run ./gradlew -PideVersion=IC-2023.3.3 :plugin-core:test --tests 'AppMapConfigFileTest.readConfigWithPath'
34+
run ./gradlew :plugin-core:test --tests 'AppMapConfigFileTest.readConfigWithPath'
3635
assert_success
3736

3837
output="$(< tmp/appmap/junit/appland_config_AppMapConfigFileTest_readConfigWithPath.appmap.json)"

0 commit comments

Comments
 (0)