github/github-mcp-server · info

failed to marshal alert: %w

Error message

failed to marshal alert: %w

What it means

Returned if json.Marshal fails on the *github.SecretScanningAlert returned by the API. The go-github struct contains only JSON-safe field types (strings, ints, pointers, time.Time), so encoding/json cannot fail on it in practice; this branch is defensive dead code. A real occurrence would indicate a corrupted object or an incompatible go-github version, not a runtime condition.

Source

Thrown at pkg/github/secret_scanning.go:90

				return ghErrors.NewGitHubAPIErrorResponse(ctx,
					fmt.Sprintf("failed to get alert with number '%d'", alertNumber),
					resp,
					err,
				), nil, nil
			}
			defer func() { _ = resp.Body.Close() }()

			if resp.StatusCode != http.StatusOK {
				body, err := io.ReadAll(resp.Body)
				if err != nil {
					return nil, nil, fmt.Errorf("failed to read response body: %w", err)
				}
				return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get alert", resp, body), nil, nil
			}

			r, err := json.Marshal(alert)
			if err != nil {
				return nil, nil, fmt.Errorf("failed to marshal alert: %w", err)
			}

			result := utils.NewToolResultText(string(r))
			// Secret scanning alerts are access-restricted regardless of repo
			// visibility and surface the matched secret material itself, so the
			// label is always private-untrusted.
			result = attachStaticIFCLabel(ctx, deps, result, ifc.LabelSecurityAlert())
			return result, nil, nil
		},
	)
}

func ListSecretScanningAlerts(t translations.TranslationHelperFunc) inventory.ServerTool {
	schema := &jsonschema.Schema{
		Type: "object",
		Properties: map[string]*jsonschema.Schema{
			"owner": {
				Type:        "string",

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. No runtime action needed - treat any occurrence as a bug and report it upstream with the go-github version in go.mod
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && strings.Contains(err.Error(), "failed to marshal alert") {
    // json.Marshal of a plain go-github struct cannot fail: report as bug
    log.Error("impossible marshal failure on SecretScanningAlert", "err", err)
}

Prevention

When it happens

Trigger: No realistic API call produces this; marshaling a plain data struct with no channels, funcs, or cycles cannot return UnsupportedTypeError or UnsupportedValueError.

Common situations: Not observed in practice; developers only meet it while reading the handler code.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/d30c7dbc59f25a48. Report an issue: GitHub.