{"record":{"id":"f2ff9c98aa47b434","repo":"charmbracelet/glow","slug":"unable-to-open-file-w","errorCode":null,"errorMessage":"unable to open file: %w","messagePattern":"unable to open file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":143,"sourceCode":"\t\t\t\t\tsrc = &source{r, u}\n\n\t\t\t\t\t// abort filepath.Walk\n\t\t\t\t\treturn errors.New(\"source found\")\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\n\t\tif src != nil {\n\t\t\treturn src, nil\n\t\t}\n\n\t\treturn nil, errors.New(\"missing markdown source\")\n\t}\n\n\tr, err := os.Open(arg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to open file: %w\", err)\n\t}\n\tu, err := filepath.Abs(arg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get absolute path: %w\", err)\n\t}\n\treturn &source{r, u}, nil\n}\n\n// validateStyle checks if the style is a default style, if not, checks that\n// the custom style exists.\nfunc validateStyle(style string) error {\n\tif style != \"auto\" && styles.DefaultStyles[style] == nil {\n\t\tstyle = utils.ExpandPath(style)\n\t\tif _, err := os.Stat(style); errors.Is(err, fs.ErrNotExist) {\n\t\t\treturn fmt.Errorf(\"specified style does not exist: %s\", style)\n\t\t} else if err != nil {\n\t\t\treturn fmt.Errorf(\"unable to stat file: %w\", err)\n\t\t}","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/charmbracelet/glow/blob/e3970c813d93da1ea84edfca90c289d9afb82242/main.go#L125-L161","documentation":"This is the last-resort branch of sourceFromArg: the argument was not a URL and not a directory, so glow tries os.Open(arg) as a file. Failure means the file could not be opened - it is missing, permission denied, or a dangling symlink - with the raw OS error wrapped with %w. Unlike the directory branch, no existence check happens before the open.","triggerScenarios":"Path does not exist (ENOENT); file exists but is not readable by the current user (EACCES); dangling symlink; special file that cannot be opened in the current context.","commonSituations":"Typos in filenames, running as a different user than the file owner, files with 0600 permissions owned elsewhere, scripts invoking glow with unquoted paths that get split by the shell.","solutions":["Check existence and readability: ls -l <path>","Fix permissions (chmod +r) or run with appropriate privileges","Verify the path spelling and the current working directory for relative paths"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func readableFile(path string) error {\n\tfi, err := os.Stat(path)\n\tif err != nil { return err }\n\tif fi.IsDir() { return fmt.Errorf(\"%s is a directory\", path) }\n\tif fi.Mode().Perm()&0o400 == 0 { return fmt.Errorf(\"%s is not readable\", path) }\n\treturn nil\n}","typeGuard":"func isNotExist(err error) bool { return errors.Is(err, fs.ErrNotExist) }","tryCatchPattern":null,"preventionTips":["Stat paths (exists, is a regular file, readable) before invoking glow","Quote paths containing spaces in shell commands","Distinguish not-exist from permission errors in error messages"],"tags":["filesystem","io","cli-input"],"backgroundTag":null,"analyzedSha":"e3970c813d93da1ea84edfca90c289d9afb82242","analyzedAt":"2026-08-15T22:50:54.304Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}