Skip to content

Commit

Permalink
Merge pull request #51 from fayccal/panic_fix
Browse files Browse the repository at this point in the history
Fix panic error when file is not found
  • Loading branch information
aligator authored Feb 10, 2022
2 parents 37aa6d9 + 842b0f0 commit 31bbbee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/goslice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"github.com/aligator/goslice"
"github.com/aligator/goslice/data"
"io"
"os"

"github.com/aligator/goslice"
"github.com/aligator/goslice/data"

flag "github.com/spf13/pflag"
)

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 31bbbee

Please sign in to comment.