Skip to content
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

[bug] Errors interrupt spinner, producing screen output harder to interpret #2353

Closed
heaths opened this issue Jun 5, 2023 · 0 comments · Fixed by #2362
Closed

[bug] Errors interrupt spinner, producing screen output harder to interpret #2353

heaths opened this issue Jun 5, 2023 · 0 comments · Fixed by #2362

Comments

@heaths
Copy link
Member

heaths commented Jun 5, 2023

When an error occurs, any spinner text gets broken up and somewhat duplicated across lines because the error is written to stderr (or stdout, whichever) just like the spinner. The main culprit seems to because the spinner isn't stopped first, which is what we do in the GitHub CLI.

This:

// Deploys the Azure infrastructure for the specified project
func (m *Manager) Deploy(ctx context.Context, plan *DeploymentPlan) (*DeployResult, error) {
	// Apply the infrastructure deployment
	deployResult, err := m.provider.Deploy(ctx, plan)
	if err != nil {
		return nil, fmt.Errorf("error deploying infrastructure: %w", err)
	}

	if err := UpdateEnvironment(m.env, deployResult.Deployment.Outputs); err != nil {
		return nil, fmt.Errorf("updating environment with deployment outputs: %w", err)
	}

	// make sure any spinner is stopped
	m.console.StopSpinner(ctx, "", input.StepDone)

	return deployResult, nil
}

Should be more like this:

// Deploys the Azure infrastructure for the specified project
func (m *Manager) Deploy(ctx context.Context, plan *DeploymentPlan) (*DeployResult, error) {
        // make sure any spinner is stopped
        defer  m.console.StopSpinner(ctx, "", input.StepDone)

	// Apply the infrastructure deployment
	deployResult, err := m.provider.Deploy(ctx, plan)
	if err != nil {
		return nil, fmt.Errorf("error deploying infrastructure: %w", err)
	}

	if err := UpdateEnvironment(m.env, deployResult.Deployment.Outputs); err != nil {
		return nil, fmt.Errorf("updating environment with deployment outputs: %w", err)
	}

	return deployResult, nil
}

Since you're only return an error, you could use defer to stop the spinner. The trickier part is when you have any code actally writing the error to stderr/stdout. Then you want to make sure you're more explicit about stopping the error.

@ghost ghost added the needs-triage For new issues label Jun 5, 2023
heaths added a commit to heaths/azure-dev that referenced this issue Jun 6, 2023
@ghost ghost removed the needs-triage For new issues label Jun 6, 2023
heaths added a commit that referenced this issue Jun 7, 2023
* Make sure spinner is stopped appropriately

Fixes #2353

* Update CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants