hashicorp/nomad · error

failed to convert "%s" to UTF16: %v

Error message

failed to convert "%s" to UTF16: %v

What it means

After resolving the absolute path, diskInfo() converts it to a UTF-16 pointer via syscall.UTF16PtrFromString, required by the Windows API. This error is returned when the conversion fails — almost always because the path contains an embedded NUL byte (\x00), which Windows strings cannot carry.

Source

Thrown at client/fingerprint/storage_windows.go:28

)

//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zstorage_windows.go storage_windows.go

//sys	getDiskSpaceEx(dirName *uint16, availableFreeBytes *uint64, totalBytes *uint64, totalFreeBytes *uint64) (err error) = kernel32.GetDiskFreeSpaceExW

// diskInfo inspects the filesystem for path and returns the volume name and
// the total bytes available on the file system.
func (f *StorageFingerprint) diskInfo(path string) (volume string, total uint64, err error) {
	absPath, err := filepath.Abs(path)
	if err != nil {
		return "", 0, fmt.Errorf("failed to determine absolute path for %s", path)
	}

	volume = filepath.VolumeName(absPath)

	absPathp, err := syscall.UTF16PtrFromString(absPath)
	if err != nil {
		return "", 0, fmt.Errorf("failed to convert \"%s\" to UTF16: %v", absPath, err)
	}

	if err := getDiskSpaceEx(absPathp, nil, &total, nil); err != nil {
		return "", 0, fmt.Errorf("failed to get free disk space for %s: %v", absPath, err)
	}

	return volume, total, nil
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Sanitize the volume path to remove NUL bytes before it reaches the fingerprint (strings.ReplaceAll(p, "\x00", ""))
  2. Check where the path originates (config file, env var, plugin output) and fix the producer of the malformed string
  3. Re-run the fingerprint with a simple known-good path like 'C:\\' to confirm the host is healthy

Example fix

// before
path := someConfiguredPath // may contain "\x00"
// after
path := strings.ReplaceAll(someConfiguredPath, "\x00", "")
Defensive patterns

Strategy: validation

Validate before calling

if strings.ContainsRune(path, '\x00') {
    return fmt.Errorf("volume path %q contains NUL byte and cannot be converted to UTF16", path)
}
if _, err := syscall.UTF16FromString(path); err != nil {
    return fmt.Errorf("path %q is not valid for Windows APIs: %v", path, err)
}

Type guard

func isUTF16SafePath(p string) bool {
    _, err := syscall.UTF16FromString(p)
    return err == nil
}

Try / catch

volume, total, err := fp.diskInfo(path)
if err != nil {
    if strings.Contains(err.Error(), "to UTF16") {
        log.Printf("malformed volume path %q, sanitizing", path)
        return fp.diskInfo(strings.ReplaceAll(path, "\x00", ""))
    }
    return err
}

Prevention

When it happens

Trigger: Storage fingerprint on Windows where syscall.UTF16PtrFromString(absPath) errors, typically because the volume path string contains a NUL byte.

Common situations: Path data read from config or environment carries a stray NUL byte; a driver or plugin returns a malformed path; heap-corruption-adjacent string bugs surfacing as 'invalid argument'.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/600a2d743be1609a. Report an issue: GitHub.