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
- Sanitize the volume path to remove NUL bytes before it reaches the fingerprint (strings.ReplaceAll(p, "\x00", ""))
- Check where the path originates (config file, env var, plugin output) and fix the producer of the malformed string
- 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
- Never build paths via byte-slices that may carry trailing NUL bytes
- Prefer utf16-safe helpers (golang.org/x/sys/windows) over raw syscall strings
- Log the raw path bytes when path-related errors occur to spot hidden NULs
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
- failed to determine absolute path for %s
- failed to get free disk space for %s: %v
- failed to convert username to UTF-16: %w
- failed to convert user domain to UTF-16: %w
- missing accessor ID
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/600a2d743be1609a.
Report an issue: GitHub.