kopia/kopia · error

error preparing pushover notification

Error message

error preparing pushover notification

What it means

The pushover sender's Send serializes its payload with json.Marshal and then builds the HTTP request; both failures are wrapped as 'error preparing pushover notification' (this instance is the marshaling step). It means the payload could not be converted to JSON before the request is sent.

Solutions

  1. Inspect the wrapped error via errors.Unwrap to identify the offending field.
  2. Ensure all payload fields (message, title, etc.) are plain JSON-serializable types.
  3. Fix or remove custom MarshalJSON implementations used in payload values.
  4. Sanitize numeric fields to avoid NaN/Inf values before calling Send.

Example fix

// before
payload["priority"] = computedPriority // may be NaN
// after
if math.IsNaN(computedPriority) { computedPriority = 0 }
payload["priority"] = computedPriority
Defensive patterns

Strategy: validation

Validate before calling

func preflightPushoverPayload(payload map[string]any) error {
  _, err := json.Marshal(payload)
  return err
}

Try / catch

if err := p.Send(ctx, msg); err != nil {
  if strings.Contains(err.Error(), "error preparing pushover notification") {
    return fmt.Errorf("pushover payload failed to build (check serializable fields and endpoint URL): %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling Send on a pushover provider whose payload contains a value json.Marshal cannot serialize (unsupported type, invalid float like NaN/Inf, or a MarshalJSON returning an error).

Common situations: Placing non-serializable values (channels, funcs, NaN) into the message/title/URL fields; custom option types added to the payload struct; corrupted Endpoint option does NOT cause this error (it only affects the request build).

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 kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/a8cd17c801f290b5. Report an issue: GitHub.

Appendix: source

Thrown at notification/sender/pushover/pushover_sender.go:44

func (p *pushoverProvider) Send(ctx context.Context, msg *sender.Message) error {
	payload := map[string]string{
		"token":   p.opt.AppToken,
		"user":    p.opt.UserKey,
		"message": msg.Subject + "\n\n" + msg.Body,
	}

	if p.Format() == "html" {
		payload["html"] = "1"
	}

	targetURL := defaultPushoverURL
	if p.opt.Endpoint != "" {
		targetURL = p.opt.Endpoint
	}

	body, err := json.Marshal(payload)
	if err != nil {
		return errors.Wrap(err, "error preparing pushover notification")
	}

	req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetURL, bytes.NewReader(body))
	if err != nil {
		return errors.Wrap(err, "error preparing pushover notification")
	}

	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return errors.Wrap(err, "error sending pushover notification")
	}

	defer resp.Body.Close() //nolint:errcheck

	if resp.StatusCode != http.StatusOK {
		return errors.Errorf("error sending pushover notification: %v", resp.Status)

View on GitHub (pinned to 82495e54b5)