]> git.lizzy.rs Git - micro.git/commitdiff
Don't crash if only file to open is directory
authorZachary Yedidia <zyedidia@gmail.com>
Thu, 2 Jan 2020 20:25:07 +0000 (15:25 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Thu, 2 Jan 2020 20:25:07 +0000 (15:25 -0500)
cmd/micro/micro.go
internal/buffer/buffer.go

index 152681d4ca1d415ee41da10eaafc592fc1d2215b..910706a438030d583aa0809e8d4998a4f61bf080 100644 (file)
@@ -5,6 +5,7 @@ import (
        "fmt"
        "io/ioutil"
        "os"
+       "runtime"
        "sort"
 
        "github.com/go-errors/errors"
@@ -208,6 +209,13 @@ func main() {
        }()
 
        b := LoadInput()
+
+       if len(b) == 0 {
+               // No buffers to open
+               screen.Screen.Fini()
+               runtime.Goexit()
+       }
+
        action.InitTabs(b)
        action.InitGlobals()
 
index 16bc28f794e1129d0c9ce33e36dfd7d94f90838f..c9f56f50fa96cf4bb142fc94b1230972e324be9a 100644 (file)
@@ -133,7 +133,7 @@ func NewBufferFromFile(path string, btype BufType) (*Buffer, error) {
        fileInfo, _ := os.Stat(filename)
 
        if err == nil && fileInfo.IsDir() {
-               return nil, errors.New(filename + " is a directory")
+               return nil, errors.New("Error: " + filename + " is a directory and cannot be opened")
        }
 
        defer file.Close()