t8y2/dbx · error

read Hive initFile: %w

Error message

read Hive initFile: %w

What it means

readHiveInitFile opens the configured initFile with os.Open and wraps any failure with this message. The initFile contains SQL statements executed at session start, so the driver cannot honor the initialization contract if the file can't be opened. The %w preserves the OS cause (not found, permission denied, is-a-directory).

Source

Thrown at agents/drivers/argo-go/config.go:1170

func prefixedParameters(values map[string]string, prefix string) map[string]string {
	result := map[string]string{}
	for key, value := range values {
		if len(key) <= len(prefix) || !strings.EqualFold(key[:len(prefix)], prefix) {
			continue
		}
		name := strings.TrimSpace(key[len(prefix):])
		if name != "" {
			result[name] = value
		}
	}
	return result
}

func readHiveInitFile(path string) ([]string, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, fmt.Errorf("read Hive initFile: %w", err)
	}
	defer file.Close()

	var script strings.Builder
	scanner := bufio.NewScanner(file)
	scanner.Buffer(make([]byte, 0, 64*1024), 16*1024*1024)
	for scanner.Scan() {
		line := strings.TrimSpace(scanner.Text())
		if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "--") {
			continue
		}
		script.WriteString(line)
		script.WriteByte(' ')
	}
	if err := scanner.Err(); err != nil {
		return nil, fmt.Errorf("read Hive initFile: %w", err)
	}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Verify the initFile path exists and is readable before connecting (os.Stat)
  2. Use an absolute path or embed the init SQL via go:embed instead of a file path
  3. Mount the init file into the container/deployment
  4. If initialization is optional, clear the initFile parameter rather than pointing at a missing file

Example fix

// before
//go:embed ignored by build tags; initFile="init.sql"
// after
//go:embed init.sql
var initSQL string // pass via supported mechanism or ensure file ships with the binary
Defensive patterns

Strategy: validation

Validate before calling

if initFile != "" {
    fi, err := os.Stat(initFile)
    if err != nil || fi.IsDir() {
        return fmt.Errorf("initFile not a readable file: %s", initFile)
    }
}

Try / catch

if err := db.PingContext(ctx); err != nil {
    if errors.Is(err, os.ErrNotExist) && strings.Contains(err.Error(), "read Hive initFile") {
        log.Fatalf("initFile missing: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Connecting with the initFile parameter set while os.Open fails: path typo, file absent on the client host, no read permission, or path points to a directory.

Common situations: initFile created on a dev machine but not packaged with the deployed app; relative path resolved against a different working directory in production; file removed by cleanup jobs; container slim image omitted the SQL file.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/01fd206160acfe38. Report an issue: GitHub.