Fix crash when creating a new note fails (#83)

This commit is contained in:
Mickaël Menu 2021-09-30 09:03:37 +02:00 committed by GitHub
parent dc27a7dd7c
commit 977dc20bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,15 +42,17 @@ func (cmd *New) Run(container *cli.Container) error {
Extra: cmd.Extra,
Date: time.Now(),
})
path := filepath.Join(notebook.Path, note.Path)
if err != nil {
var path string
if err == nil {
path = filepath.Join(notebook.Path, note.Path)
} else {
var noteExists core.ErrNoteExists
if !errors.As(err, &noteExists) {
return err
}
if confirmed, _ := container.Terminal.Confirm(
fmt.Sprintf("%s already exists, do you want to edit this note instead?", note.Path),
fmt.Sprintf("%s already exists, do you want to edit this note instead?", noteExists.Name),
true,
); !confirmed {
// abort...