Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
lucacome committed Oct 22, 2025
commit 1fd0396899be4be622732819a9f63cf22216ce1a
19 changes: 7 additions & 12 deletions internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func SelectRegion(ctx context.Context) (string, error) {
regionNames, err := GetRegions(ctx)
if err != nil {
if ctx.Err() != nil {
return "", ctx.Err()
return "", fmt.Errorf("operation canceled: %w", ctx.Err())
}
return "", fmt.Errorf("failed to retrieve regions: %w", err)
}
Expand All @@ -66,15 +66,10 @@ func SelectRegion(ctx context.Context) (string, error) {

err = form.RunWithContext(ctx)
if err != nil {
select {
case <-ctx.Done():
return "", ctx.Err()
default:
if err.Error() == "^C" {
return "", context.Canceled
}
return "", fmt.Errorf("failed to select region: %w", err)
if ctxErr := ctx.Err(); ctxErr != nil {
return "", fmt.Errorf("region selection canceled: %w", ctxErr)
}
return "", fmt.Errorf("failed to select region: %w", err)
}

return selectedRegion, nil
Expand Down Expand Up @@ -135,9 +130,9 @@ func UpdateExitNode(ctx context.Context, c *tsapi.Client, id string) error {
var currentExitNodeName string
if status.ExitNodeStatus != nil {
// Get all devices to find the current exit node name
devices, err := c.Devices().List(ctx)
if err != nil {
return fmt.Errorf("failed to get devices: %w", err)
devices, errList := c.Devices().List(ctx)
if errList != nil {
return fmt.Errorf("failed to get devices: %w", errList)
}

// Find the device that matches the current exit node ID
Expand Down
14 changes: 10 additions & 4 deletions tailout/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
tsapi "tailscale.com/client/tailscale/v2"
)

var ErrUserAborted = errors.New("user aborted instance creation")

func (app *App) Create(ctx context.Context) error {
nonInteractive := app.Config.NonInteractive
region := app.Config.Region
Expand Down Expand Up @@ -101,6 +103,10 @@ func (app *App) Create(ctx context.Context) error {

runInput, errPrep := prepareInstance(ctx, cfg, aws.Bool(dryRun))
if errPrep != nil {
if errors.Is(errPrep, ErrUserAborted) {
fmt.Println("Instance creation aborted.")
return nil
}
return fmt.Errorf("failed to prepare instance: %w", errPrep)
}
if runInput == nil {
Expand All @@ -113,12 +119,12 @@ func (app *App) Create(ctx context.Context) error {
var instanceID string
s := spinner.New().Type(spinner.Dots).Title("Creating instance...")
errSpin := s.Context(ctx).ActionWithErr(func(context.Context) error {
instance, createErr := createInstance(ctx, cfg, runInput, key.Key, s)
instance, createErr := createInstance(ctx, cfg, runInput, s)
if createErr != nil {
return createErr
}
if instance.InstanceID == "" {
return fmt.Errorf("instance creation aborted")
return errors.New("instance creation aborted")
}
instanceID = instance.InstanceID
nodeName = instance.Name
Expand Down Expand Up @@ -289,12 +295,12 @@ sudo echo "sudo shutdown" | at now + ` + strconv.Itoa(10) + ` minutes`
}

if !result {
return nil, nil
return nil, ErrUserAborted
}
return runInput, nil
}

func createInstance(ctx context.Context, cfg aws.Config, runInput *ec2.RunInstancesInput, key string, spin *spinner.Spinner) (instance instance, err error) {
func createInstance(ctx context.Context, cfg aws.Config, runInput *ec2.RunInstancesInput, spin *spinner.Spinner) (instance instance, err error) {
ec2Svc := ec2.NewFromConfig(cfg)

// Run the EC2 instance
Expand Down
6 changes: 3 additions & 3 deletions tailout/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func (app *App) Stop(ctx context.Context, args []string) error {
return nil
}

nodesToStop = make([]tsapi.Device, len(selectedIndices))
for i, idx := range selectedIndices {
nodesToStop[i] = tailoutNodes[idx]
nodesToStop = make([]tsapi.Device, 0, len(selectedIndices))
for _, idx := range selectedIndices {
nodesToStop = append(nodesToStop, tailoutNodes[idx])
}
} else {
if !stopAll {
Expand Down
Loading