Skip to content

Fix panic on missing sketch path #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2019
Merged
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
29 changes: 25 additions & 4 deletions cli/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -52,18 +54,37 @@ var attachFlags struct {

func runAttachCommand(cmd *cobra.Command, args []string) {
instance := instance.CreateInstance()
var path string
if len(args) > 0 {
path = args[1]

var path *paths.Path
if len(args) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

uhm.. shouldn't be > 0?

Copy link
Member

Choose a reason for hiding this comment

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

ah I see, forget it, 1 is correct.

path = paths.New(args[1])
} else {
path = initSketchPath(path)
}

_, err := board.Attach(context.Background(), &rpc.BoardAttachReq{
Instance: instance,
BoardUri: args[0],
SketchPath: path,
SketchPath: path.String(),
SearchTimeout: attachFlags.searchTimeout,
}, output.TaskProgress())
if err != nil {
feedback.Errorf("Attach board error: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
}

// initSketchPath returns the current working directory
func initSketchPath(sketchPath *paths.Path) *paths.Path {
if sketchPath != nil {
return sketchPath
}

wd, err := paths.Getwd()
if err != nil {
feedback.Errorf("Couldn't get current working directory: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
logrus.Infof("Reading sketch from dir: %s", wd)
return wd
}