Skip to content

Disable preview option in prompts if URL size is too long#3271

Merged
mislav merged 2 commits intocli:trunkfrom
cristiand391:disable-preview-long-url
Mar 30, 2021
Merged

Disable preview option in prompts if URL size is too long#3271
mislav merged 2 commits intocli:trunkfrom
cristiand391:disable-preview-long-url

Conversation

@cristiand391
Copy link
Contributor

Fixes #1575

This PR adds an additional check to pr/issue create to disable Continue in browser option if the preview URL max size (8192 bytes) is exceeded.

@cristiand391
Copy link
Contributor Author

Is there a way to test that a specific option hasn't been rendered by survey? I've only added tests for --web flag + long URL case.

Also, I'm not sure how should gh warn that Continue in browser has been disabled intentionally; specifically when a user edit the body manually in their editor and the prompt is already rendered.

@samcoe
Copy link
Contributor

samcoe commented Mar 22, 2021

@cristiand391 As far as I know we don't have a good way to automatically test that the option is not being rendered by survey. For now manually checking that it is disabled is the best avenue.

For a first iteration I am okay with not displaying any warning that the preview option has been disabled because I expect it is a fairly rare case that the url will be greater than 8192 bytes but @mislav might have another opinion.

Overall this code looks solid to me. Thanks for the contribution.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

To let users know why the "Continue in browser" option is not presented to them, we could print a line to stderr just before calling ConfirmSubmission(). This isn't strictly necessary, but if someone is used to choosing "Continue in browser", they might find it weird that the option is mysteriously not present at some times but present at other times.

Is there a way to test that a specific option hasn't been rendered by survey? I've only added tests for --web flag + long URL case.

No, I don't think this is easy to do right now, so you are free to just skip that and test it manually. 👌

Comment on lines +167 to +169
if err != nil {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like this condition is needed

return
}
if !utils.ValidURL(openURL) {
return fmt.Errorf("Failed to create URL: maximum URL length exceeded")
Copy link
Contributor

Choose a reason for hiding this comment

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

Due to our failure recovery mechanism in issue/pr create, new errors should first be assigned to err before they are returned.

Suggested change
return fmt.Errorf("Failed to create URL: maximum URL length exceeded")
err = fmt.Errorf("Failed to create URL: maximum URL length exceeded")
return

Copy link
Contributor Author

@cristiand391 cristiand391 Mar 23, 2021

Choose a reason for hiding this comment

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

Do you think gh should offer recover instructions for this error?
I tried assigning errors to err but it in order to make it work I had to move the defer statement preserveInput right before this block.

@mislav mislav force-pushed the disable-preview-long-url branch from a0b9cb6 to 57536e7 Compare March 30, 2021 17:12
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Fantastic. Thank you so much for the hard work!

@mislav mislav merged commit 79219c7 into cli:trunk Mar 30, 2021
@cristiand391 cristiand391 deleted the disable-preview-long-url branch March 30, 2021 20:06
ZIMkaRU added a commit to ZIMkaRU/bfx-report-electron that referenced this pull request Jun 2, 2021
ZIMkaRU added a commit to ZIMkaRU/bfx-report-electron that referenced this pull request Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP 414: Request-URI too large

3 participants