BoundaryML/baml · error

failed open source %s: %w

Error message

failed open source %s: %w

What it means

Filesystem error in the Go client library's toolchain downloader: os.Open failed on the local source path while copying a file (part of staging the downloaded baml library). The wrapped os error in %w carries the OS-level reason (permissions, missing file); the path is echoed so the failing file is identifiable.

Source

Thrown at engine/language_client_go/baml_go/lib_common.go:638

}

func isHex(s string) bool {
	if len(s) == 0 {
		return false
	}
	for _, r := range s {
		if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f') || (r >= 'A' && r <= 'F')) {
			return false
		}
	}
	return true
}

func copyFile(src, dst string) (err error) {
	logger.Debug("Attempting to copy file", "source", src, "destination", dst)
	source, err := os.Open(src)
	if err != nil {
		return fmt.Errorf("failed open source %s: %w", src, err)
	}
	defer source.Close()

	destination, err := os.Create(dst)
	if err != nil {
		return fmt.Errorf("failed create destination %s: %w", dst, err)
	}
	defer func() {
		cerr := destination.Close()
		if err == nil && cerr != nil {
			err = fmt.Errorf("failed close destination %s: %w", dst, cerr)
		}
	}()

	_, err = io.Copy(destination, source)
	if err != nil {
		return fmt.Errorf("failed copying from %s to %s: %w", src, dst, err)
	}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Re-run the download to recreate the temp file
  2. Ensure no concurrent process or temp-cleaner deletes files mid-install (use a private temp dir)
  3. Check permissions on the temp directory
  4. If this recurs, check disk health — odd ENOENT/EIO on fresh files can indicate disk issues

Example fix

// before: shared /tmp, cleaned by other processes
tmpFile, _ := os.CreateTemp("/tmp", "baml-*")
// after: private temp dir owned by the process
dir, _ := os.MkdirTemp("", "baml-dl")
tmpFile, _ := os.CreateTemp(dir, "lib-*")
Defensive patterns

Strategy: retry

Validate before calling

if _, err := os.Stat(src); err != nil {
    return fmt.Errorf("temp file missing before copy: %w", err)
}

Try / catch

if err := install(); err != nil {
    if strings.Contains(err.Error(), "failed open source") {
        os.Remove(src); return install() // recreate temp and retry
    }
    return err
}

Prevention

When it happens

Trigger: os.Open(src) fails during the copy fallback — the temp file was deleted by a concurrent process or cleaner before the copy, or permissions on the temp file/dir changed.

Common situations: /tmp cleaner removing files mid-download, another concurrent download process racing on the same temp file, or running with a different umask/user than the downloader.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/da1a44d1fa7881a0. Report an issue: GitHub.