Skip to content

Commit

Permalink
Handle file not found error
Browse files Browse the repository at this point in the history
Print extra message if installed via snap.

Fixes #38
  • Loading branch information
mapitman committed Dec 31, 2024
1 parent a338592 commit e5a451e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit e5a451e

Please sign in to comment.