JuliusBrussee/caveman · error

kms: encode %s request: %w

Error message

kms: encode %s request: %w

What it means

Client.call wraps the json.Marshal failure while serializing the KMS operation request body (encrypt or decrypt input map). Marshaling a map[string]string essentially never fails — this is a defensive wrap; the at-fault input would be an unexpected value in the operation's input map.

Source

Thrown at shared/platform/kms/kms.go:349

		return errors.New("kms: probe plaintext mismatch")
	}
	return nil
}

func validateLocation(region, keyID string) error {
	if !regionPattern.MatchString(region) {
		return errors.New("kms: invalid Scaleway region")
	}
	if !keyIDPattern.MatchString(keyID) {
		return errors.New("kms: invalid Scaleway key ID")
	}
	return nil
}

func (c *Client) call(ctx context.Context, region, keyID, operation string, input, output any) error {
	body, err := json.Marshal(input)
	if err != nil {
		return fmt.Errorf("kms: encode %s request: %w", operation, err)
	}
	endpoint := c.apiBaseURL + "/key-manager/v1alpha1/regions/" + url.PathEscape(region) +
		"/keys/" + url.PathEscape(keyID) + "/" + operation
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("kms: create %s request: %w", operation, err)
	}
	req.Header.Set("content-type", "application/json")
	req.Header.Set("accept", "application/json")
	req.Header.Set("x-auth-token", c.token)
	resp, err := c.httpClient.Do(req)
	if err != nil {
		return fmt.Errorf("kms: %s request failed: %w", operation, err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 32<<10))
		return fmt.Errorf("kms: %s returned HTTP %d", operation, resp.StatusCode)

View on GitHub (pinned to 766dce6b13)

Solutions

  1. Retry; this error is unexpected for string-map request bodies
  2. Inspect the wrapped error to identify the problematic input value
  3. Report as a bug if reproducible with valid plaintext/ciphertext inputs
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at shared/platform/kms/kms.go:349 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/9c44df9d1eee83b5. Report an issue: GitHub.