wtfutil/wtf · warning

failed to marshal request: %v

Error message

failed to marshal request: %v

What it means

ConvertJQLWithUsername fails when json.Marshal cannot serialize the JQL conversion request body before POSTing it to Jira's /rest/api/3/jql/pdcleaner. In practice this is near-impossible with the simple request struct, so the error almost always indicates a programming/structural fault rather than an environment problem.

Source

Thrown at modules/jira/client.go:124

// ConvertJQLWithUsername converts a JQL query containing username to account ID
func (widget *Widget) ConvertJQLWithUsername(username string) (string, error) {
	// Check cache first
	if accountID, found := userIDCache.Get(username); found {
		return fmt.Sprintf("assignee = \"%s\"", accountID), nil
	}

	// Create a JQL query with the username that needs conversion
	originalJQL := fmt.Sprintf("assignee = \"%s\"", username)

	// Prepare the request body
	requestBody := JQLConversionRequest{
		QueryStrings: []string{originalJQL},
	}

	// Convert to JSON
	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		return "", fmt.Errorf("failed to marshal request: %v", err)
	}

	// Make the POST request to the JQL conversion API
	resp, err := widget.jiraPostRequest("/rest/api/3/jql/pdcleaner", jsonData)
	if err != nil {
		return "", err
	}

	var conversionResult JQLConversionResponse
	err = utils.ParseJSON(&conversionResult, bytes.NewReader(resp))
	if err != nil {
		return "", err
	}

	if len(conversionResult.QueryStrings) == 0 {
		return "", fmt.Errorf("no conversion result for username: %s", username)
	}

View on GitHub (pinned to bb838c1ccb)

Solutions

  1. Inspect the error detail (%v) to identify the unmarshalable value
  2. Review recent changes to the request struct in client.go for unsupported field types
  3. Restore the original requestBody definition or make added fields JSON-serializable

Example fix

// before
requestBody := struct {
    Callback chan int `json:"callback"` // unmarshalable
    QueryStrings []string
}{...}
// after
requestBody := struct {
    QueryStrings []string `json:"queryStrings"`
}{QueryStrings: []string{originalJQL}}
Defensive patterns

Strategy: try-catch

Try / catch

query, err := widget.ConvertJQLWithUsername(username)
if err != nil {
    if strings.HasPrefix(err.Error(), "failed to marshal request") {
        log.Printf("client bug: request struct not serializable: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ConvertJQLWithUsername when the internal requestBody value cannot be marshaled - essentially only if the struct or QueryStrings field is replaced with an unmarshalable type (chan, func, invalid map key) in a code change.

Common situations: Custom forks or modifications to the Jira client that add unserializable fields to the request struct; not something users hit through configuration.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of wtfutil/wtf@bb838c1ccb (2026-09-03). Data as JSON: /api/errors/4dbf12fadc1c09fe. Report an issue: GitHub.