Skip to content
Open
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
7 changes: 6 additions & 1 deletion create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ func CreateWithTemplate(db *sql.DB, dir string, tmpl *template.Template, name, m
}

path := filepath.Join(dir, filename)
if _, err := os.Stat(path); !os.IsNotExist(err) {
_, err := os.Stat(path)
if err != nil && !os.IsNotExist(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest replacing this with the code mentioned in the documentation to os.IsNotExist function
!errors.Is(err, fs.ErrNotExist)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this code could be simplidfied in fort of fast failure:

_, err := os.Stat(path)
if err == nil {
	return fmt.Errorf("failed to create migration file: %w", os.ErrExist)
}

if !errors.Is(err, fs.ErrNotExist){
        return fmt.Errorf("failed to create migration file: %w", err)
}

return fmt.Errorf("failed to create migration file: %w", err)
}

if err == nil {
return fmt.Errorf("failed to create migration file: %w", os.ErrExist)
}

f, err := os.Create(path)
if err != nil {
return fmt.Errorf("failed to create migration file: %w", err)
Expand Down