{"record":{"id":"9a7744e380d677d5","repo":"siyuan-note/siyuan","slug":"get-current-bazaar-index-failed-w-get-legacy-ba","errorCode":null,"errorMessage":"get current bazaar index failed: %w; get legacy bazaar index failed: %v","messagePattern":"get current bazaar index failed: %w; get legacy bazaar index failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/bazaar/index.go","lineNumber":177,"sourceCode":"}\n\nfunc snapshotBazaarIndex(now time.Time) (snapshot *bazaarIndexSnapshot, fresh, canRetry bool) {\n\tbazaarIndexState.mu.RLock()\n\tdefer bazaarIndexState.mu.RUnlock()\n\tsnapshot = bazaarIndexState.snapshot\n\tfresh = nil != snapshot && now.Before(bazaarIndexState.expiresAt)\n\tcanRetry = bazaarIndexState.retryAt.IsZero() || !now.Before(bazaarIndexState.retryAt)\n\treturn\n}\n\nfunc fetchBazaarIndex(ctx context.Context) (ret *bazaarIndexSnapshot, err error) {\n\tret, err = fetchBazaarIndexPath(ctx, bazaarIndexPath)\n\tif nil == err {\n\t\treturn\n\t}\n\tlegacy, legacyErr := fetchBazaarIndexPath(ctx, bazaarLegacyIndexPath)\n\tif nil != legacyErr {\n\t\treturn nil, fmt.Errorf(\"get current bazaar index failed: %w; get legacy bazaar index failed: %v\", err, legacyErr)\n\t}\n\treturn legacy, nil\n}\n\nfunc fetchBazaarIndexPath(ctx context.Context, indexPath string) (ret *bazaarIndexSnapshot, err error) {\n\ttimeBucket := bazaarIndexNow().Unix() / int64(bazaarIndexCDNBucket/time.Second)\n\tu := fmt.Sprintf(\"%s%s?t=%d\", bazaarIndexStatServer, indexPath, timeBucket)\n\tbuf := &bytes.Buffer{}\n\tresp, err := httpclient.NewBrowserRequest().SetRetryCount(0).SetContext(ctx).SetOutput(buf).Get(u)\n\tif nil != err {\n\t\treturn nil, err\n\t}\n\tif 200 != resp.StatusCode {\n\t\treturn nil, fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}\n\treturn parseBazaarIndex(buf.Bytes())\n}\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/bazaar/index.go#L159-L195","documentation":"fetchBazaarIndex tries the current CDN bazaar index path first and falls back to the legacy path. This error wraps both failures: the primary fetch error (%w) and the legacy fetch error (%v). It means neither the current nor the legacy index endpoint could be reached or parsed, so no bazaar index snapshot is available.","triggerScenarios":"The background index refresh calls fetchBazaarIndex and fetchBazaarIndexPath fails for both bazaarIndexPath and bazaarLegacyIndexPath — e.g. network is down, both CDN URLs return non-200 (see index.go:191), or both payloads fail parseBazaarIndex validation.","commonSituations":"Total loss of internet connectivity; bazaar CDN outage affecting both index URLs; a server-side change publishing invalid index JSON to both paths; DNS or proxy blocking the bazaar host; unit tests forcing both paths to fail.","solutions":["Fix the underlying connectivity problem so at least one of the two index URLs is reachable","Check whether the bazaar server is publishing a valid index; a single fixed server-side index resolves this client-side","Rely on the cached snapshot if one exists (snapshotBazaarIndex serves stale data while refresh fails) and retry after network recovery","Inspect the wrapped errors (%w primary and %v legacy) separately — the primary error usually names the real cause (status code, timeout, parse failure)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"snapshot, err := fetchBazaarIndex(ctx)\nif err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) || strings.Contains(err.Error(), \"unexpected status code\") {\n        // schedule a retry with backoff; serve stale cached snapshot meanwhile\n    }\n}","preventionTips":["Serve the last cached snapshot while refreshes fail instead of erroring to users","Retry with exponential backoff — CDN outages are usually transient","Alert on server-side index publication failures, since both paths failing usually means the publisher is broken"],"tags":["network","marketplace","fallback-exhausted"],"backgroundTag":"upstream-api-error","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}