Skip to content

Commit

Permalink
Merge pull request #289 from getappmap/fix/config-packages-key-missin…
Browse files Browse the repository at this point in the history
…g-value

fix: crash due to config packages key with missing value
  • Loading branch information
apotterri authored Aug 21, 2024
2 parents 011a645 + 26714d8 commit 34059ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ static AppMapConfig load(Path configFile, boolean mustExist) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
singleton = mapper.readValue(inputStream, AppMapConfig.class);
if (singleton.packages == null) {
logger.error("AppMap: missing value for the 'packages' entry in appmap.yml");
return null;
}
} catch (IOException e) {
logger.error("AppMap: encountered syntax error in appmap.yml {}", e.getMessage());
System.exit(1);
return null;
}
singleton.configFile = configFile;
logger.debug("config: {}", singleton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ public void hasAppmapDir() throws Exception {
AppMapConfig.load(configFile, true);
assertEquals("/appmap", AppMapConfig.get().getAppmapDir());
}

@Test
public void loadPackagesKeyWithMissingValue() throws Exception {
Path configFile = tmpdir.resolve("appmap.yml");
final String contents = "name: test\npackages:\npath: xyz";
Files.write(configFile, contents.getBytes());
String actualErr = tapSystemErr(() -> AppMapConfig.load(configFile, false));
assertTrue(actualErr.contains("AppMap: missing value for the 'packages'"));
}

@Test
public void loadPackagesKeyWithScalarValue() throws Exception {
Path configFile = Files.createTempFile("appmap", ".yml");
final String contents = "name:q test\npackages: abc\n";
Files.write(configFile, contents.getBytes());
String actualErr = tapSystemErr(() -> AppMapConfig.load(configFile, false));
assertTrue(actualErr.contains("AppMap: encountered syntax error in appmap.yml"));
}
}


3 changes: 1 addition & 2 deletions agent/test/intellij/intellij.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ setup() {
}

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

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

0 comments on commit 34059ae

Please sign in to comment.