go-playground/validator · error
*PathError from os.Stat
Error message
*PathError from os.Stat
What it means
Panics inside the dir_path validator when os.Stat returns an error that is not one of the recognized syscall cases (e.g. not EINVAL for invalid characters and not a benign not-exist case). The code documents that os.Stat errors are *PathError values; hitting the default switch branch means something unexpectedly serious went wrong stat-ing the path (such as a path longer than the filesystem limit or an exotic I/O fault), so it panics with the raw error rather than silently passing or failing the validation.
Source
Thrown at baked_in.go:2986
if t.Err == syscall.EINVAL {
// It's definitely an invalid character in the path.
return false
}
// It could be a permission error, a does-not-exist error, etc.
// Out-of-scope for this validation, though.
// Lastly, we make sure it is a directory.
if strings.HasSuffix(field.String(), string(os.PathSeparator)) {
return true
} else {
return false
}
default:
// Something went *seriously* wrong.
/*
Per https://pkg.go.dev/os#Stat:
"If there is an error, it will be of type *PathError."
*/
panic(err)
}
}
// We repeat the check here to make sure it is an explicit directory in case the above os.Stat didn't trigger an error.
if strings.HasSuffix(field.String(), string(os.PathSeparator)) {
return true
} else {
return false
}
}
panic(fmt.Sprintf("Bad field type %s", field.Type()))
}
// isJSON is the validation function for validating if the current field's value is a valid json string.
func isJSON(fl FieldLevel) bool {
field := fl.Field()
switch field.Kind() {View on GitHub (pinned to facf128d2e)
Solutions
- Check the underlying *PathError to identify the real filesystem failure
- Shorten the path if it exceeds the OS path-length limit
- Ensure the process has the required permissions on parent directories
- Wrap the validation call in a recover if untrusted paths must never crash the service
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at baked_in.go:2986 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of go-playground/validator@facf128d2e (2026-09-02).
Data as JSON: /api/errors/2cacf541ec914118.
Report an issue: GitHub.