Skip to content

Commit

Permalink
Applying file existence check in reader.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fayccal committed Feb 10, 2022
1 parent 6295550 commit 842b0f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 1 addition & 7 deletions cmd/goslice/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -28,17 +27,12 @@ func main() {
os.Exit(1)
}

if _, err := os.Stat(o.GoSlice.InputFilePath); errors.Is(err, os.ErrNotExist) {
_, _ = fmt.Fprintf(os.Stderr, "the file doesn't exist\n")
os.Exit(2)
}

p := goslice.NewGoSlice(o)
err := p.Process()

if err != nil {
fmt.Println("error while processing file:", err)
os.Exit(3)
os.Exit(2)
}
}

Expand Down
6 changes: 6 additions & 0 deletions reader/reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package reader

import (
"errors"
"os"

"github.com/aligator/goslice/data"
"github.com/aligator/goslice/handler"
"github.com/hschendel/stl"
Expand Down Expand Up @@ -110,6 +113,9 @@ func Reader(options *data.Options) handler.ModelReader {

func (r reader) Read(filename string) (data.Model, error) {
model := &model{}
if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
return model, os.ErrNotExist
}
stl.CopyFile(filename, model)
return model, nil
}
Expand Down

0 comments on commit 842b0f0

Please sign in to comment.