v2rayA/v2rayA · error

anytls: marshal settings: %w

Error message

anytls: marshal settings: %w

What it means

Wrapping error from AnyTLS.Configuration() in service/kernel/serverObj/anytls.go:88. It is returned when json.Marshal fails while serializing the anytlsSettings struct (address, port, password, SNI, pinned cert, etc.) into the outbound settings JSON for the xray config. Since the struct contains only plain strings/ints/bools, this marshal step is effectively infallible; seeing it means an extreme internal failure, not a user configuration problem.

Source

Thrown at service/kernel/serverObj/anytls.go:88

	if u.User != nil {
		password = u.User.Username()
	}
	q := u.Query()
	sni := q.Get("sni")
	minIdle, _ := strconv.Atoi(q.Get("minIdleSession"))

	settingsJSON, err := json.Marshal(anytlsSettings{
		Address:                          s.Server,
		Port:                             s.Port,
		Password:                         password,
		SNI:                              sni,
		MinIdleSessions:                  minIdle,
		AllowInsecure:                    s.AllowInsecure,
		PinnedPeerCertificateChainSha256: q.Get("pinnedPeerCertSha256"),
		VerifyPeerCertByName:             q.Get("verifyPeerCertByName"),
	})
	if err != nil {
		return c, fmt.Errorf("anytls: marshal settings: %w", err)
	}

	return Configuration{
		CoreOutbound: coreObj.OutboundObject{
			Tag:      info.Tag,
			Protocol: "anytls",
			Settings: coreObj.Settings{Inlined: settingsJSON},
		},
		UDPSupport: true,
	}, nil
}

func (s *AnyTLS) ExportToURL() string {
	return s.Link
}

func (s *AnyTLS) NeedPluginPort() bool {
	return false

View on GitHub (pinned to 71e5442fc5)

Solutions

  1. Verify the link parses correctly first: ensure the anytls:// URL has a valid host and integer port, since Configuration is only reached after ParseAnyTLSURL succeeded.
  2. Rebuild v2rayA from unmodified sources; a patched coreObj or anytlsSettings with a faulty MarshalJSON is the only realistic cause.
  3. Update to a released v2rayA version; report the full wrapped error text if it persists on stock builds.
  4. If you only need the node to work, re-import the anytls share link (valid syntax: anytls://password@host:port?sni=...&allow_insecure=true#name).

Example fix

// The error is thrown, not caught — no caller-side fix applies.
// Maintainer-side sanity check that the struct stays JSON-marshalable:
if _, err := json.Marshal(anytlsSettings{Address: "host", Port: 443}); err != nil {
    log.Fatal("anytls settings not marshalable: %v", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: ensure the anytls link parses and fields are sane before Configuration
u, err := url.Parse(link)
if err != nil || u.Port() == "" {
    return fmt.Errorf("invalid anytls link: %w", err)
}
if _, err := strconv.Atoi(u.Port()); err != nil {
    return fmt.Errorf("invalid anytls port: %w", err)
}

Type guard

// Narrow with the registered constructor before use:
obj, err := serverObj.NewAnyTLS(link)
if err != nil {
    // not a usable anytls node; skip Configuration
    return err
}
anytls, ok := obj.(*serverObj.AnyTLS)
if !ok {
    return fmt.Errorf("unexpected server obj type")
}

Try / catch

c, err := anytlsServer.Configuration(info)
if err != nil {
    if strings.Contains(err.Error(), "anytls: marshal settings") {
        // internal serialization failure — escalate, not a user-fixable issue
        return fmt.Errorf("internal error building anytls outbound: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling AnyTLS.Configuration(info) (reached by adding/pinging an anytls:// node) and json.Marshal of the anytlsSettings struct returns an error — practically only via a custom unsupported json.Marshaler on a field type or an unrecoverable encoding/json internal failure.

Common situations: Almost never hit in practice; theoretically encountered when building with a modified coreObj/anytlsSettings type that implements MarshalJSON and returns an error, or when the struct gains a channel/func-like custom marshaler.

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 v2rayA/v2rayA@71e5442fc5 (2026-09-05). Data as JSON: /api/errors/67afd2abe2277fc9. Report an issue: GitHub.