Skip to content

Do not use terminal escape sequences in non-interactive terminals or the Windows command prompt.#2327

Merged
mitchell-as merged 9 commits intoversion/0-36-0-RC1from
mitchell/dx-1527-2
Jan 30, 2023
Merged

Do not use terminal escape sequences in non-interactive terminals or the Windows command prompt.#2327
mitchell-as merged 9 commits intoversion/0-36-0-RC1from
mitchell/dx-1527-2

Conversation

@mitchell-as
Copy link
Copy Markdown
Collaborator

@mitchell-as mitchell-as commented Jan 26, 2023

BugDX-1527 Occasional panic errors and continues gibberish during runtime progress on Windows

@github-actions github-actions Bot changed the base branch from version/0-36-0-RC1 to version/0-36-0-RC1 January 26, 2023 21:53
@mitchell-as mitchell-as reopened this Jan 26, 2023
@mitchell-as mitchell-as requested a review from Naatan January 26, 2023 22:20
@mitchell-as mitchell-as marked this pull request as ready for review January 26, 2023 22:20
Copy link
Copy Markdown
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Interactivity isn't the issue here. My forgetting to address cmd.exe when I implemented this is. There's a lib I found that should handle it cross-platform:

https://github.com/atomicgo/cursor

BUT it has the same issue as your code; it assumes windows==cmd.exe, whereas in reality windows also runs bash, and it's not an uncommon use-case.

That said; you can probably use the lib above to figure out how to do it with cmd.exe. I realize this is more of a missed functionality issue than a bug though, so if this turns into a timesink we could descope the windows implementation and utilize interactive=false for windows for the bug (but please only if it turns into a timesink).

Regardless of which route we go; it's not the job of the output package to assert interactive or detect shells. So we'll want to find a way to pass that in externally, this seems like a reasonable location:

https://github.com/ActiveState/cli/blob/4e7692e37d5d9602945a34fb352faed519d21c8e/cmd/state/output.go#L59

For shell detection we can use the logic here:

https://github.com/ActiveState/cli/blob/4e7692e37d5d9602945a34fb352faed519d21c8e/internal/subshell/subshell.go#L91

I suggest splitting that out into its own function so we don't have to do subshell.New().

There's a lot in my response here.. happy to jump on zoom to go over things in greater detail.

Comment thread internal/output/progress.go Outdated
@mitchell-as mitchell-as force-pushed the mitchell/dx-1527-2 branch 2 times, most recently from 1646927 to a734da7 Compare January 27, 2023 17:22
@mitchell-as
Copy link
Copy Markdown
Collaborator Author

I ended up using subshell.New() because it doesn't look very expensive and the result is cleaner. I could switch it to subshell.DetectShellBinary() and check the file basename for cmd.exe if you prefer.

@mitchell-as mitchell-as requested a review from Naatan January 27, 2023 19:03
Comment thread cmd/state/main.go Outdated
// Set up our output formatter/writer
outFlags := parseOutputFlags(os.Args)
out, err := initOutput(outFlags, "")
out, err := initOutput(outFlags, "", subshell.New(cfg).Shell())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd still like to advocate splitting the shell detection logic out. It's true that New() isn't very costly, but it's still doing more than we need it to. Plus we don't know how it will evolve in the future, nor will we be sensitive to this use-case in the future unless we make it explicit.

Comment thread internal/output/progress.go
Comment thread internal/output/progress_unix.go Outdated
package output

func (d *Spinner) moveCaretBackInCommandPrompt(n int) {
// No-op
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's send a rollbar error if this happens, since it should never happen.

Copy link
Copy Markdown
Collaborator Author

@mitchell-as mitchell-as Jan 27, 2023

Choose a reason for hiding this comment

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

I thought about that, but then we'll hammer rollbar on every tick in a worst-case scenario.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could just only send it the first time. Record it to something like Spinner.recorded = true.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Aye, but is there a chance we'll be creating a large number of these progress objects? We'd still be in the same boat.

Comment thread internal/output/progress_win.go Outdated
This allows the current shell name/path to be found without creating a new subshell.
@mitchell-as
Copy link
Copy Markdown
Collaborator Author

Let me know if I missed something extracting the shell detection logic into its own function.

@mitchell-as mitchell-as requested a review from Naatan January 27, 2023 21:40
Copy link
Copy Markdown
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Please also see my replies to previous comments.

}
binary = resolveBinaryPath(binary)

}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be part of the shell detection.

@mitchell-as mitchell-as requested a review from Naatan January 27, 2023 22:24
Copy link
Copy Markdown
Contributor

@Naatan Naatan left a comment

Choose a reason for hiding this comment

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

Nice, the subshell stuff looks much more readable!

@mitchell-as mitchell-as merged commit 80bb36a into version/0-36-0-RC1 Jan 30, 2023
@mitchell-as mitchell-as deleted the mitchell/dx-1527-2 branch January 30, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants