Skip to content

Commit 09f1846

Browse files
committed
fix(tomcat): propagate WEB-INF stat/Glob errors, clarify multi-WAR warning
- os.Stat(WEB-INF) non-NotExist errors now fail fast instead of silently falling into the packaged-WAR path - filepath.Glob errors now returned instead of silently skipped - Multi-WAR warning message clarified: 'cannot determine which to deploy, skipping context descriptor generation' instead of 'context_path not applied' (the latter was misleading when context_path was not set)
1 parent f659310 commit 09f1846

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/java/containers/tomcat.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,11 @@ func (t *TomcatContainer) Finalize() error {
581581
contextXMLPath := filepath.Join(t.tomcatDir(), "conf", "Catalina", "localhost", contextXMLName)
582582

583583
webInf := filepath.Join(buildDir, "WEB-INF")
584-
if _, err := os.Stat(webInf); err == nil {
584+
_, webInfErr := os.Stat(webInf)
585+
if webInfErr != nil && !os.IsNotExist(webInfErr) {
586+
return fmt.Errorf("failed to check WEB-INF directory: %w", webInfErr)
587+
}
588+
if webInfErr == nil {
585589
// the script name is prefixed with 'zzz' as it is important to be the last script sourced from profile.d
586590
// so that the previous scripts assembling the CLASSPATH variable(left from frameworks) are sourced previous to it.
587591
if err := t.context.Stager.WriteProfileD("zzz_classpath_symlinks.sh", fmt.Sprintf(symlinkScript, filepath.Join("WEB-INF", "lib"))); err != nil {
@@ -631,7 +635,10 @@ func (t *TomcatContainer) Finalize() error {
631635
}
632636
} else {
633637
warMatches, err := filepath.Glob(filepath.Join(buildDir, "*.war"))
634-
if err == nil && len(warMatches) == 1 {
638+
if err != nil {
639+
return fmt.Errorf("failed to find WAR files in build directory: %w", err)
640+
}
641+
if len(warMatches) == 1 {
635642
warFilename := filepath.Base(warMatches[0])
636643
contextContent := fmt.Sprintf("<Context docBase=\"${user.home}/app/%s\" reloadable=\"false\">\n</Context>\n", warFilename)
637644

@@ -659,7 +666,7 @@ func (t *TomcatContainer) Finalize() error {
659666
}
660667
}
661668
} else if len(warMatches) > 1 {
662-
t.context.Log.Warning("Multiple WAR files found in build directory; context_path not applied")
669+
t.context.Log.Warning("Multiple WAR files found in build directory; cannot determine which to deploy, skipping context descriptor generation")
663670
}
664671
}
665672

0 commit comments

Comments
 (0)