{"record":{"id":"67afd2abe2277fc9","repo":"v2rayA/v2rayA","slug":"anytls-marshal-settings-w","errorCode":null,"errorMessage":"anytls: marshal settings: %w","messagePattern":"anytls: marshal settings: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/kernel/serverObj/anytls.go","lineNumber":88,"sourceCode":"\tif u.User != nil {\n\t\tpassword = u.User.Username()\n\t}\n\tq := u.Query()\n\tsni := q.Get(\"sni\")\n\tminIdle, _ := strconv.Atoi(q.Get(\"minIdleSession\"))\n\n\tsettingsJSON, err := json.Marshal(anytlsSettings{\n\t\tAddress:                          s.Server,\n\t\tPort:                             s.Port,\n\t\tPassword:                         password,\n\t\tSNI:                              sni,\n\t\tMinIdleSessions:                  minIdle,\n\t\tAllowInsecure:                    s.AllowInsecure,\n\t\tPinnedPeerCertificateChainSha256: q.Get(\"pinnedPeerCertSha256\"),\n\t\tVerifyPeerCertByName:             q.Get(\"verifyPeerCertByName\"),\n\t})\n\tif err != nil {\n\t\treturn c, fmt.Errorf(\"anytls: marshal settings: %w\", err)\n\t}\n\n\treturn Configuration{\n\t\tCoreOutbound: coreObj.OutboundObject{\n\t\t\tTag:      info.Tag,\n\t\t\tProtocol: \"anytls\",\n\t\t\tSettings: coreObj.Settings{Inlined: settingsJSON},\n\t\t},\n\t\tUDPSupport: true,\n\t}, nil\n}\n\nfunc (s *AnyTLS) ExportToURL() string {\n\treturn s.Link\n}\n\nfunc (s *AnyTLS) NeedPluginPort() bool {\n\treturn false","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/service/kernel/serverObj/anytls.go#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Rebuild v2rayA from unmodified sources; a patched coreObj or anytlsSettings with a faulty MarshalJSON is the only realistic cause.","Update to a released v2rayA version; report the full wrapped error text if it persists on stock builds.","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)."],"exampleFix":"// The error is thrown, not caught — no caller-side fix applies.\n// Maintainer-side sanity check that the struct stays JSON-marshalable:\nif _, err := json.Marshal(anytlsSettings{Address: \"host\", Port: 443}); err != nil {\n    log.Fatal(\"anytls settings not marshalable: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Go: ensure the anytls link parses and fields are sane before Configuration\nu, err := url.Parse(link)\nif err != nil || u.Port() == \"\" {\n    return fmt.Errorf(\"invalid anytls link: %w\", err)\n}\nif _, err := strconv.Atoi(u.Port()); err != nil {\n    return fmt.Errorf(\"invalid anytls port: %w\", err)\n}","typeGuard":"// Narrow with the registered constructor before use:\nobj, err := serverObj.NewAnyTLS(link)\nif err != nil {\n    // not a usable anytls node; skip Configuration\n    return err\n}\nanytls, ok := obj.(*serverObj.AnyTLS)\nif !ok {\n    return fmt.Errorf(\"unexpected server obj type\")\n}","tryCatchPattern":"c, err := anytlsServer.Configuration(info)\nif err != nil {\n    if strings.Contains(err.Error(), \"anytls: marshal settings\") {\n        // internal serialization failure — escalate, not a user-fixable issue\n        return fmt.Errorf(\"internal error building anytls outbound: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate anytls:// share links (host + integer port) at import time so Configuration only sees well-formed nodes","Keep v2rayA on stock builds where settings structs are guaranteed JSON-marshalable","Treat this error as a bug-report trigger, not a retryable condition","Add a CI test that marshals every serverObj settings struct"],"tags":["go","configuration","json-marshal","anytls"],"backgroundTag":"json-marshal-failed","analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}