siyuan-note/siyuan · error

asset path must be absolute

Error message

asset path must be absolute

What it means

dataRelativeAssetPath validates that an asset path is absolute before computing its path relative to the workspace data directory. A relative path cannot be anchored to DataDir, so the kernel refuses it outright. This is an internal caller-contract check: every caller must pass a fully resolved absolute path.

Solutions

  1. Resolve the path against util.DataDir before calling: filepath.Join(util.DataDir, filepath.FromSlash(rel))
  2. Use GetAssetAbsPath to convert a documented asset link into an absolute path
  3. Assert filepath.IsAbs(absPath) at the caller boundary to fail fast

Example fix

// before
model.EnsureAssetLocal("assets/foo.png")
// after
abs := filepath.Join(util.DataDir, filepath.FromSlash("assets/foo.png"))
model.EnsureAssetLocal(abs)
Defensive patterns

Strategy: validation

Validate before calling

func ensureAbs(p string) string {
    if !filepath.IsAbs(p) {
        return filepath.Join(util.DataDir, filepath.FromSlash(p))
    }
    return p
}

Try / catch

if err := model.EnsureAssetLocal(p); err != nil && strings.Contains(err.Error(), "must be absolute") {
    p = filepath.Join(util.DataDir, filepath.FromSlash(p))
    err = model.EnsureAssetLocal(p)
}

Prevention

When it happens

Trigger: EnsureAssetLocal or EnsureAssetPrefixLocal receives a relative path like `assets/foo.png` or `./assets` instead of `/home/user/SiYuan/data/assets/foo.png`.

Common situations: Plugin or API caller passing the workspace-relative path stored in the document instead of resolving it against DataDir; code written on Windows using forward-slash relative paths; refactored code dropping a filepath.Join(util.DataDir, ...) step.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/asset_download.go:117

	if Conf.Sync == nil || !Conf.Sync.Enabled || Conf.GetUser() == nil {
		return errors.New(Conf.Language(376))
	}
	switch Conf.Sync.Provider {
	case conf.ProviderSiYuan:
		if !IsSubscriber() {
			return errors.New(Conf.Language(376))
		}
	case conf.ProviderS3, conf.ProviderWebDAV, conf.ProviderLocal:
		if !IsPaidUser() {
			return errors.New(Conf.Language(376))
		}
	}
	return nil
}

func dataRelativeAssetPath(absPath string) (string, error) {
	if !filepath.IsAbs(absPath) {
		return "", fmt.Errorf("asset path must be absolute")
	}
	rel, err := filepath.Rel(util.DataDir, filepath.Clean(absPath))
	if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
		return "", fmt.Errorf("asset path is outside data directory")
	}
	if rel == "." {
		return "/", nil
	}
	return "/" + filepath.ToSlash(rel), nil
}

// EnsureAssetLocal 在调用方完成访问校验后补齐资源,下载内容仍由原有读取流程认证。
func EnsureAssetLocal(absPath string) error {
	if _, err := os.Stat(absPath); err == nil {
		return nil
	} else if !errors.Is(err, os.ErrNotExist) {
		return err
	}

View on GitHub (pinned to 9f775e8a12)