Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle file not found error #39

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {"SNAP_USER_COMMON": "mark"},
"args": ["bad-perms.md"]
// "env": {"SNAP_USER_COMMON": "mark"},
"args": ["README.md"]
}
]
}
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"crypto/rand"
_ "embed"
"encoding/hex"
"errors"
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -114,13 +116,18 @@ func getTempDir() string {

func check(e error) {
if e != nil {
if os.IsPermission(e) {
if errors.Is(e, fs.ErrPermission) {
fmt.Println("There was a permission error accessing the file.")
if isSnap() {
fmt.Println("Since mdview was installed as a Snap, it can only access files in your HOME directory.")
fmt.Println("If you need to use it with files outside of your HOME directory, choose a different installation method.")
fmt.Println("https://github.com/mapitman/mdview?tab=readme-ov-file#installation\n")
}
}

if errors.Is(e, fs.ErrNotExist) {
fmt.Println("mdview was unable to find the file.")
}

if isSnap() {
fmt.Println("Since mdview was installed as a Snap, it can only access files in your HOME directory.")
fmt.Println("If you need to use it with files outside of your HOME directory, choose a different installation method.")
fmt.Println("https://github.com/mapitman/mdview?tab=readme-ov-file#installation\n")
}

log.Fatal(e)
Expand All @@ -143,6 +150,7 @@ func getTitle(tokens []markdown.Token) string {
}
}
}

return result
}

Expand Down
Loading