Skip to content

[WIP] Preserve user input when PR/Issue creation fails - #2313

Closed
vilmibm wants to merge 14 commits into
trunkfrom
dumps
Closed

vilmibm wants to merge 14 commits into
trunkfrom
dumps

Conversation

@vilmibm

@vilmibm vilmibm commented Oct 28, 2020 •

Copy link
Copy Markdown
Contributor

Closes #906

This is a proposal for mitigating failed pr/issue creation.

image

Preserved input can be restored (including metadata) like this:

image

notes

  • body can be copied and pasted more easily with jq .Body
  • whole preserved payload can be restored with --json option
  • didn't put in issue create yet, wanted to get feedback

questions

  • do we want input saving for other operations?
  • is json reasonable? i'm thinking i could add a --json flag to [pr|issue] create that could ingest a json file which has utility beyond just recovering from failure
  • is using temp dir instead of current working directory reasonable?

@vilmibm
vilmibm marked this pull request as draft October 28, 2020 20:14
Comment thread pkg/cmd/pr/shared/preserve_input.go Outdated

func PreserveInput(io *iostreams.IOStreams, ims *IssueMetadataState, defs Defaults, doPreserve *bool) func() {
return func() {
if ims.Body == defs.Body && ims.Title == defs.Title {

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.

Considering that the metadata state has more information than just the body and title I don't know if this check against the default body and title is very valuable. I would say that in the cases of failure where we want to dump the output we should write to disk whatever information we have regardless of what it is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i want a check like this so if someone ctrl-c's immediately we don't litter the filesystem; but I'm realizing I should just augment it with nil checks for metadata.

Comment thread pkg/cmd/pr/shared/preserve_input.go Resolved
Comment thread pkg/cmd/pr/shared/preserve_input.go Outdated
// this extra newline guards against appending to the end of a survey line
fmt.Fprintln(out)

data, err := json.Marshal(ims)

@samcoe samcoe Oct 29, 2020 •

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 like writing the output in json, as it allows flexibility for if we want to add in recovery options later on but is still usable to end users right away using jq.

Comment thread pkg/cmd/pr/create/create.go Outdated
}

doPreserveInput := false
defer shared.PreserveInput(opts.IO, &tb, defs, &doPreserveInput)()

@samcoe samcoe Oct 29, 2020 •

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 may be too much magic but I was wondering if we could do something like https://play.golang.org/p/Fu9C96Gcr-C so that we don't need to tell the PreserveInput function when to preserve the input or not, it would be able to check if the calling function was going to return an error and then do its work if so. This path would entail refactoring createRun to have a named output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mm, i'm open to that. we don't tend to use named outputs but i think it could help, here

@ampinsk

ampinsk commented Oct 29, 2020

Copy link
Copy Markdown

is json reasonable? i'm thinking i could add a --json flag to [pr|issue] create that could ingest a json file which has utility beyond just recovering from failure

I'd really like for this to be a part of the flow! Without it, I feel like we're still leaving people at a dead end unless we give them a way to use that output to try again.

Building off of that, could we remember this file and prompt the user with some kind of "try again?" option? Maybe when you run pr/issue create the next time, we could prompt with something like "Try again with recovered input?"

@vilmibm

vilmibm commented Oct 29, 2020

Copy link
Copy Markdown
Contributor Author

Building off of that, could we remember this file and prompt the user with some kind of "try again?" option? Maybe when you run pr/issue create the next time, we could prompt with something like "Try again with recovered input?"

we can certainly try that; I'll start with the --restore flag and then we can see how an automatic prompt feels.

@vilmibm

vilmibm commented Nov 3, 2020

Copy link
Copy Markdown
Contributor Author

Updated with --json option; screenshot added to body.

I think for now I'd rather restoring be manual. The current state of this PR is a better situation than what we have now in trunk and, if it turns out to be sufficient, means we don't have to manage a prompt that might get annoying if not implemented properly.

Since there's been no objection to the approach up til now I'll expand this to cover issue creation and add tests.

@ampinsk

ampinsk commented Nov 5, 2020

Copy link
Copy Markdown

@vilmibm I'm totally fine with just the json flag, but could we add a hint to the error to use it to restore?

@vilmibm

vilmibm commented Nov 13, 2020

Copy link
Copy Markdown
Contributor Author

switching to #2408

@vilmibm vilmibm closed this Nov 13, 2020
@mislav
mislav deleted the dumps branch March 23, 2021 11:47
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.

Friendlier recovery when issue/pr create fails

3 participants