Skip to content

Conversation

@Jbekker
Copy link
Contributor

@Jbekker Jbekker commented Sep 12, 2025

This is to resolve two open issues, #176 and #41

  1. Adds error handling to ParseOpenShellResponse so that users have the ability to retry opening a shell when this fails.
  2. It makes the private err field on the command accessible, similar to c.exitCode.

@anurag5sh
Copy link

@masterzen this would solve some long standing issues in packer

Copy link
Owner

@masterzen masterzen left a comment

Choose a reason for hiding this comment

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

Sorry for the late review, I was abroad with few network access.
This looks correct and I'm inclined to merge the PR, but would you mind taking a look at my suggestions?
Thanks!

@Jbekker
Copy link
Contributor Author

Jbekker commented Sep 22, 2025

Since the ParseOpenShellResponse and ParseExecuteCommandResponse functions are now almost identical, we could also extract the common parts into it's own function so you get something like this:

What are your thoughts on that?

func parseResponse(response string, expectedAction, idXPath, errorMsg string) (string, error) {
	...
}

func ParseOpenShellResponse(response string) (string, error) {
	return parseResponse(
		response,
		"http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse",
		"//rsp:ShellId",
		"error during shell creation",
	)
}

func ParseExecuteCommandResponse(response string) (string, error) {
	return parseResponse(
		response,
		"http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandResponse",
		"//rsp:CommandId",
		"error during command execution",
	)
}

@masterzen
Copy link
Owner

Since the ParseOpenShellResponse and ParseExecuteCommandResponse functions are now almost identical, we could also extract the common parts into it's own function so you get something like this:

What are your thoughts on that?

Indeed, even better!
Would you mind adding a commit?
If not, we can merge as is.

@Jbekker
Copy link
Contributor Author

Jbekker commented Sep 22, 2025

Sure, I'll create a commit for this when I can. Probably tomorrow morning.

@anurag5sh
Copy link

are we good to merge this? @Jbekker

@Jbekker
Copy link
Contributor Author

Jbekker commented Sep 25, 2025

are we good to merge this? @Jbekker

We are! @masterzen, please take a look.

Copy link
Owner

@masterzen masterzen left a comment

Choose a reason for hiding this comment

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

LGTM, let's merge

@masterzen masterzen merged commit 411f4b6 into masterzen:master Sep 27, 2025
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.

3 participants