Skip to content

Commit

Permalink
Merge pull request #32428 from vespa-engine/hmusum/log-more-when-serv…
Browse files Browse the repository at this point in the history
…ices.xml-not-found

Log more about files in application package when services.xml is miss…
  • Loading branch information
bjormel authored Sep 19, 2024
2 parents cbf8eb2 + 391ff13 commit aef9d14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.logging.Logger;

import static com.yahoo.text.Lowercase.toLowerCase;
import static com.yahoo.yolean.Exceptions.uncheck;


/**
Expand Down Expand Up @@ -644,9 +645,15 @@ private void preprocess(File appDir, File dir, Zone zone) throws IOException {
private void validateServicesFile() throws IOException {
File servicesFile = getServicesFile();
if ( ! servicesFile.exists())
throw new IllegalArgumentException(SERVICES + " does not exist in application package");
throw new IllegalArgumentException(SERVICES + " does not exist in application package. " +
"There are " + filesInApplicationPackage() + " files in the directory");
if (IOUtils.readFile(servicesFile).isEmpty())
throw new IllegalArgumentException(SERVICES + " in application package is empty");
throw new IllegalArgumentException(SERVICES + " in application package is empty. " +
"There are " + filesInApplicationPackage() + " files in the directory");
}

private long filesInApplicationPackage() {
return uncheck(() -> Files.list(appDir.toPath()).count());
}

private void copyUserDefsIntoApplication() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public void failOnMissingServicesXml() throws IOException {
FilesApplicationPackage app = FilesApplicationPackage.fromFile(appDir);
var exception = assertThrows(IllegalArgumentException.class,
() -> app.preprocess(new Zone(Environment.dev, RegionName.defaultName()), new BaseDeployLogger()));
assertEquals("services.xml does not exist in application package", exception.getMessage());
String message = exception.getMessage();
assertTrue(message.startsWith("services.xml does not exist in application package"));
assertTrue(message.contains("There are 4 files in the directory"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void testBadZipDeployment() throws Exception {
"""
{
"error-code": "BAD_REQUEST",
"message": "Error preprocessing application package for test.default, session 2: services.xml does not exist in application package"
"message": "Error preprocessing application package for test.default, session 2: services.xml does not exist in application package. There are 1 files in the directory"
}
""");
}
Expand Down

0 comments on commit aef9d14

Please sign in to comment.