argoproj/argo-workflows · error

failed to create request: %w

Error message

failed to create request: %w

What it means

getAndStoreArtifactData builds the artifact download request with http.NewRequestWithContext using the argo server URL plus namespace/workflow/node/artifact path segments. This error wraps any failure from http.NewRequestWithContext, which in practice only fails if the constructed URL is malformed (unparseable host or path with illegal characters).

Source

Thrown at cmd/argo/commands/cp.go:128

	command.Flags().StringVar(&nodeID, "node-id", "", "id of node in workflow")
	command.Flags().StringVar(&templateName, "template-name", "", "name of template in workflow")
	command.Flags().StringVar(&artifactName, "artifact-name", "", "name of output artifact in workflow")
	command.Flags().StringVar(&customPath, "path", "{namespace}/{workflowName}/{nodeId}/outputs/{artifactName}", "use variables {workflowName}, {nodeId}, {templateName}, {artifactName}, and {namespace} to create a customized path to store the artifacts; example: {workflowName}/{templateName}/{artifactName}")
	return command
}

func newArtifactHTTPClient(opts apiclient.ArgoServerOpts) (*http.Client, error) {
	tlsConfig, err := tlsutil.GetClientTLSConfig(opts.ClientCert, opts.ClientKey, opts.CACert, opts.InsecureSkipVerify)
	if err != nil {
		return nil, err
	}
	return &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}, nil
}

func getAndStoreArtifactData(ctx context.Context, namespace string, workflowName string, nodeID string, artifactName string, fileName string, customPath string, c *http.Client, argoServerOpts apiclient.ArgoServerOpts) error {
	request, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/artifacts/%s/%s/%s/%s", argoServerOpts.GetURL(), namespace, workflowName, nodeID, artifactName), nil)
	if err != nil {
		return fmt.Errorf("failed to create request: %w", err)
	}
	authString, err := client.GetAuthString(ctx)
	if err != nil {
		return err
	}
	request.Header.Set("Authorization", authString)
	resp, err := c.Do(request)
	if err != nil {
		return fmt.Errorf("request failed with: %w", err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("request failed %s", resp.Status)
	}
	artifactFilePath := filepath.Join(customPath, fileName)
	fileWriter, err := os.Create(artifactFilePath)
	if err != nil {
		return fmt.Errorf("creating file failed: %w", err)

View on GitHub (pinned to 35bff19146)

Solutions

  1. Check the resolved server URL (ARGO_SERVER / ARGO_SECURE / port) — it must be a valid absolute http(s) URL.
  2. Ensure workflow/node/artifact identifiers are standard Kubernetes names (lowercase alphanumerics, '-', '.').
  3. Print or log argoServerOpts.GetURL() when running programmatically to inspect the constructed URL.
  4. Retry with a clean environment (unset ARGO_SERVER and use port-forward + defaults) to isolate the bad value.

Example fix

// before
os.Setenv("ARGO_SERVER", "localhost:2746/path with space")
// after
os.Setenv("ARGO_SERVER", "localhost:2746")
Defensive patterns

Strategy: validation

Validate before calling

// validate the server URL before issuing requests
u, err := url.Parse(argoServerOpts.GetURL())
if err != nil || u.Scheme == "" || u.Host == "" {
  return fmt.Errorf("invalid argo server URL: %q", argoServerOpts.GetURL())
}

Type guard

func validServerURL(raw string) bool {
  u, err := url.Parse(raw)
  return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
}

Try / catch

if strings.Contains(err.Error(), "failed to create request") {
  return fmt.Errorf("check ARGO_SERVER / ArgoServerOpts.URL: %w", err)
}

Prevention

When it happens

Trigger: argoServerOpts.GetURL() returns an empty or malformed URL (misconfigured ARGO_SERVER/URL), or workflow/node/artifact names interpolated into the path contain characters that make the URL invalid.

Common situations: ARGO_SERVER unset or set to a value without scheme/host; custom characters in workflow or artifact names; programmatic misuse of apiclient.ArgoServerOpts with a bad URL.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/bb466ce1f603b023. Report an issue: GitHub.