t8y2/dbx · error

read Hive initFile: %w

Error message

read Hive initFile: %w

What it means

This error wraps os.Open failures in readHiveInitFile (config.go:1173). The driver runs SQL statements from an initFile after connecting, and this error is returned when the init file cannot be opened. The wrapped error shows the OS-level reason (not found, permission denied, is-a-directory).

Source

Thrown at agents/drivers/hive-go/config.go:1173

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 a regular readable file.
  2. Use an absolute path in the initfile parameter.
  3. Fix file permissions so the process user can read the script.
  4. Ensure the init script is included in the container image or mounted volume.

Example fix

// before
dsn := "hive://user:pass@host:10000/db?initfile=./init.sql"
// after
dsn := "hive://user:pass@host:10000/db?initfile=/etc/hive/init.sql"
Defensive patterns

Strategy: validation

Validate before calling

p := params["initfile"]
if p != "" {
    info, err := os.Stat(p)
    if err != nil || info.IsDir() {
        return fmt.Errorf("initfile not a readable file: %s", p)
    }
}

Prevention

When it happens

Trigger: The 'initfile' parameter points to a path that does not exist, is a directory, or is not readable by the process when the connector initializes the session.

Common situations: Relative initFile path that resolves differently inside a container; init script not baked into the image; read permissions after deploying as a non-root user; typo in the initfile parameter.

Related errors


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