siyuan-note/siyuan · error

failed to connect cloud server

Error message

failed to connect cloud server

What it means

Sentinel error ErrFailedToConnectCloudServer, returned by every cloud-facing function (CloudChatGPT, StartFreeTrial, DeactivateUser, SetCloudBlockReminder, LoadUploadToken, cloud shorthand ops) when the underlying httpclient POST to util.GetCloudServer() fails at the transport layer or returns a network error. It abstracts away the raw HTTP client error into a single recognizable cause.

Source

Thrown at kernel/model/cloud_service.go:40

	"fmt"
	"net/http"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
	"time"

	"github.com/88250/gulu"
	"github.com/88250/lute/parse"
	"github.com/siyuan-note/httpclient"
	"github.com/siyuan-note/logging"
	"github.com/siyuan-note/siyuan/kernel/conf"
	"github.com/siyuan-note/siyuan/kernel/task"
	"github.com/siyuan-note/siyuan/kernel/util"
)

var ErrFailedToConnectCloudServer = errors.New("failed to connect cloud server")

func CloudChatGPT(msg string, contextMsgs []string) (ret string, stop bool, err error) {
	if nil == Conf.GetUser() {
		return
	}

	payload := map[string]any{}
	var messages []map[string]any
	for _, contextMsg := range contextMsgs {
		messages = append(messages, map[string]any{
			"role":    "user",
			"content": contextMsg,
		})
	}
	messages = append(messages, map[string]any{
		"role":    "user",
		"content": msg,
	})

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Check network connectivity and that the cloud server domain is reachable (curl the /apis endpoint).
  2. Verify proxy/TLS settings are not blocking the connection; allow the cloud domain through any firewall.
  3. Retry the operation after a short delay, since the cause is often transient.
  4. If persistent, check SiYuan cloud status and the user's region (mainland China uses ld246.com).

Example fix

// before
ret, stop, err := CloudChatGPT(msg, ctx)
if err != nil { return err }

// after
ret, stop, err := CloudChatGPT(msg, ctx)
if errors.Is(err, model.ErrFailedToConnectCloudServer) {
    // surface a friendly 'network unavailable' message, offer retry
}
if err != nil { return err }
Defensive patterns

Strategy: retry

Validate before calling

// Quick reachability check before a cloud call
func cloudReachable() bool {
    c := http.Client{Timeout: 5 * time.Second}
    resp, err := c.Get(util.GetCloudServer() + "/apis/siyuan/version")
    if err != nil { return false }
    defer resp.Body.Close()
    return resp.StatusCode == http.StatusOK
}

Type guard

func isConnectionError(err error) bool { return errors.Is(err, model.ErrFailedToConnectCloudServer) }

Try / catch

var lastErr error
for attempt := 0; attempt < 3; attempt++ {
    _, _, err := model.CloudChatGPT(msg, ctx)
    if err == nil { break }
    if !errors.Is(err, model.ErrFailedToConnectCloudServer) { lastErr = err; break }
    lastErr = err
    time.Sleep(time.Duration(1<<attempt) * time.Second)
}

Prevention

When it happens

Trigger: The HTTP request to the SiYuan cloud server (liuyun.io / ld246.com) fails: DNS resolution error, connection refused/reset, TLS handshake failure, or a timeout from NewCloudRequest30s (30s). The error is set after logging.LogErrorf logs the raw cause.

Common situations: User is offline or behind a proxy/firewall blocking the cloud domain; cloud server is temporarily down; DNS misconfigured; corporate network intercepts TLS; the 30-second timeout is exceeded on a slow link.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/acb70484cbac5702. Report an issue: GitHub.