Skip to content

Commit

Permalink
Add ReadFile error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaScorpion committed Apr 6, 2021
1 parent f43b0c4 commit 9435c43
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/keyScripter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/LucaScorpion/keyScripter/internal/parser"
"github.com/alexflint/go-arg"
"io/ioutil"
"os"
)

Expand All @@ -22,8 +21,18 @@ func main() {
os.Exit(1)
}

// Read the file.
b, err := os.ReadFile(options.Script)
if err != nil {
if pathErr, ok := err.(*os.PathError); ok {
fmt.Printf("An error occurred while trying to %s", pathErr.Error())
} else {
fmt.Printf("An error occurred while trying to read the script: %s", err)
}
os.Exit(1)
}

// Parse the script.
b, _ := ioutil.ReadFile(options.Script)
script, err := parser.Parse(string(b))
if err != nil {
fmt.Printf("An error occurred while parsing the script: %s", err)
Expand Down

0 comments on commit 9435c43

Please sign in to comment.