apache/beam · error

error creating jarFile header

Error message

error creating jarFile header: %w

What it means

jarFile.CreateHeader(fileHeader) failed while adding an entry to the output zip writer in packJar. The zip.Writer could not accept the header — typically because the underlying file write failed (disk full, I/O error) or the header is invalid (e.g. oversized/invalid name).

Solutions

  1. Free space on the volume holding the output jar (df -h) and retry.
  2. Check filesystem health (dmesg / smartctl) if I/O errors appear in the wrapped message.
  3. Shorten or sanitize unusually long entry names in the source tree.
  4. Delete the partial output jar and re-run packJar from a clean state.
Defensive patterns

Strategy: validation

Validate before calling

if len(fileHeader.Name) > 1024 { return fmt.Errorf("entry name too long: %s", fileHeader.Name) }
if err := checkDiskSpace(destDir, requiredBytes); err != nil { return err }

Try / catch

writer, err := jarFile.CreateHeader(fileHeader)
if err != nil {
    if errors.Is(err, syscall.ENOSPC) { /* free space then retry */ }
    return fmt.Errorf("error creating jarFile header: %w", err)
}

Prevention

When it happens

Trigger: During the filepath.Walk callback, CreateHeader fails writing to the zip stream: ENOSPC on the destination volume, underlying jar file write I/O error, or an invalid header produced from odd file metadata.

Common situations: Full disk when repacking a large Uber JAR; destination volume with I/O errors; extremely long file names inside the extracted tree producing invalid zip entry names.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a6bcd04995892686. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:234

		}
		fileHeader, err := zip.FileInfoHeader(fileInfo)
		if err != nil {
			return fmt.Errorf("error getting FileInfoHeader: %w", err)
		}

		if sourceDir != "" {
			fileHeader.Name = filepath.Join(sourceDir, strings.TrimPrefix(path, source))
		}

		if fileInfo.IsDir() {
			fileHeader.Name += "/"
		} else {
			fileHeader.Method = zip.Deflate
		}

		writer, err := jarFile.CreateHeader(fileHeader)
		if err != nil {
			return fmt.Errorf("error creating jarFile header: %w", err)
		}
		if fileInfo.IsDir() {
			return nil
		}

		f, err := os.Open(path)
		if err != nil {
			return fmt.Errorf("error opening file %s: %w", path, err)
		}
		defer f.Close()

		if _, err = io.Copy(writer, f); err != nil {
			return fmt.Errorf("error copying file %s: %w", path, err)
		}
		return nil
	})
	return err
}

View on GitHub (pinned to 12126d8942)