Standard library / path/filepath

path/filepath.ErrBadPattern

Sentinel for malformed filepath patterns; no-match alone is not an error. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
var ErrBadPattern error

Working Example

Example Snippetgo
package main
import (  "errors"  "fmt"  "os"  "path/filepath")
func check(e error) {  if e != nil {    panic(e)  }}func workspace() func() {  root, e := os.MkdirTemp("", "bytemind-go-")  check(e)  old, e := os.Getwd()  check(e)  check(os.Chdir(root))  return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() {  defer workspace()()  _, e := filepath.Glob("[")  fmt.Println(errors.Is(e, filepath.ErrBadPattern))}
Go Reference