Skip to content

Commit f501789

Browse files
authored
Merge pull request #39 from mapitman/bug/handle-file-not-found
Handle file not found error
2 parents a338592 + e5a451e commit f501789

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"request": "launch",
1111
"mode": "auto",
1212
"program": "${workspaceFolder}",
13-
"env": {"SNAP_USER_COMMON": "mark"},
14-
"args": ["bad-perms.md"]
13+
// "env": {"SNAP_USER_COMMON": "mark"},
14+
"args": ["README.md"]
1515
}
1616
]
1717
}

main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"crypto/rand"
55
_ "embed"
66
"encoding/hex"
7+
"errors"
78
"flag"
89
"fmt"
10+
"io/fs"
911
"log"
1012
"os"
1113
"path/filepath"
@@ -114,13 +116,18 @@ func getTempDir() string {
114116

115117
func check(e error) {
116118
if e != nil {
117-
if os.IsPermission(e) {
119+
if errors.Is(e, fs.ErrPermission) {
118120
fmt.Println("There was a permission error accessing the file.")
119-
if isSnap() {
120-
fmt.Println("Since mdview was installed as a Snap, it can only access files in your HOME directory.")
121-
fmt.Println("If you need to use it with files outside of your HOME directory, choose a different installation method.")
122-
fmt.Println("https://github.com/mapitman/mdview?tab=readme-ov-file#installation\n")
123-
}
121+
}
122+
123+
if errors.Is(e, fs.ErrNotExist) {
124+
fmt.Println("mdview was unable to find the file.")
125+
}
126+
127+
if isSnap() {
128+
fmt.Println("Since mdview was installed as a Snap, it can only access files in your HOME directory.")
129+
fmt.Println("If you need to use it with files outside of your HOME directory, choose a different installation method.")
130+
fmt.Println("https://github.com/mapitman/mdview?tab=readme-ov-file#installation\n")
124131
}
125132

126133
log.Fatal(e)
@@ -143,6 +150,7 @@ func getTitle(tokens []markdown.Token) string {
143150
}
144151
}
145152
}
153+
146154
return result
147155
}
148156

0 commit comments

Comments
 (0)