siyuan-note/siyuan · error

box and dataPath cannot be used together

Error message

box and dataPath cannot be used together

What it means

resolveAssetRequestPath resolves the absolute path of an asset requested from the HTTP server. When the request supplies both a box ID and a dataPath, the two resolution modes are mutually exclusive, so the function rejects the request with this error rather than guessing which one to honor.

Solutions

  1. Remove the `box` parameter from the request when a `dataPath` is supplied (dataPath resolution is workspace-wide)
  2. Remove the `dataPath` parameter and keep only `box` if the asset lives inside a specific notebook
  3. Update client code to build only one style of asset URL

Example fix

// before
fetchPost("/assets/foo.png?box=20240101120000-abcdefg&dataPath=assets/foo.png")
// after
fetchPost("/assets/foo.png?dataPath=assets/foo.png")
Defensive patterns

Strategy: validation

Validate before calling

if (box && dataPath) throw new Error("Pass either box or dataPath, not both");

Prevention

When it happens

Trigger: Calling the asset-serving endpoint (which routes through resolveAssetRequestPath) with both a non-empty `box` query parameter and a non-empty `dataPath` query parameter.

Common situations: Frontend code or plugins that switched from box-scoped asset lookups to the dataPath-based asset URL but left the old `box` parameter in the query string; hand-built URLs combining both params.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/5207dcbac3fa9695. Report an issue: GitHub.

Appendix: source

Thrown at kernel/server/serve.go:1089

		}
		return gulu.File.IsSubPath(filepath.Join(util.DataDir, requestBoxID, "assets"), assetAbsPath)
	}

	if model.IsEncryptedAssetPath(assetAbsPath) {
		return false
	}
	dataRelativePath, err := filepath.Rel(util.DataDir, assetAbsPath)
	if err != nil {
		return false
	}
	_, validatedAbsPath, err := model.ResolveDataAssetPath(filepath.ToSlash(dataRelativePath))
	return err == nil && filepath.Clean(validatedAbsPath) == filepath.Clean(assetAbsPath)
}

func resolveAssetRequestPath(cleanPath, boxID, dataPath string) (string, error) {
	if dataPath != "" {
		if boxID != "" {
			return "", errors.New("box and dataPath cannot be used together")
		}
		dataRelativePath, assetAbsPath, err := model.ResolveDataAssetPath(dataPath)
		if err != nil {
			return "", err
		}
		assetPath, _, ok := model.AssetPathFromDataRelativePath(dataRelativePath)
		if !ok || assetPath != cleanPath {
			return "", fmt.Errorf("asset path [%s] does not match data path [%s]", cleanPath, dataPath)
		}
		return assetAbsPath, nil
	}
	if boxID != "" {
		return model.GetAssetAbsPathInBox(cleanPath, boxID)
	}
	return model.GetAssetAbsPath(cleanPath)
}

func serveAssets(ginServer *gin.Engine) {

View on GitHub (pinned to 9f775e8a12)