siyuan-note/siyuan · error
path is required
Error message
path is required
What it means
openTemplatePath resolves a user-supplied template path against the workspace templates root and requires a non-empty input. An empty string cannot be anchored relative to the templates directory, so the helper fails fast with this error instead of resolving to the root itself or an unpredictable location. It is used by ReadTemplateFile and RemoveTemplate.
Solutions
- Ensure the path argument is populated before calling; check for emptiness and return a friendly message to the user
- If the caller is config-driven, validate the template-path config field at load time
- Provide a default template path or prompt the user to select a template when the value is empty
- Fix upstream logic so the path variable is assigned before the call
Example fix
// before
content, err := model.ReadTemplateFile(cfg.TemplatePath)
// after
if cfg.TemplatePath == "" { return errors.New("no template configured") }
content, err := model.ReadTemplateFile(cfg.TemplatePath) Defensive patterns
Strategy: validation
Validate before calling
if p == "" { return errors.New("template path must be set") } Type guard
func hasTemplatePath(p string) bool { return strings.TrimSpace(p) != "" } Try / catch
if err != nil && strings.Contains(err.Error(), "path is required") {
// prompt user to choose a template
} Prevention
- Validate config fields holding template paths at startup
- Never pass through an unset variable; default or prompt instead
- Check UI selection state before invoking template APIs
When it happens
Trigger: Calling ReadTemplateFile("") or RemoveTemplate("") — i.e. passing an empty path string; also occurs when an upstream variable that should hold a template path was never populated.
Common situations: A config field or document attribute holding the template path is empty; a caller forgot to fill the path after building a request; UI state lost the selection and passed an empty string downstream.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- assetPath is required for analyze
- createDocTree requires at least one document
- method name and function required
- parent ID is required
- --path is required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/5e9248975e5a82b8.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_path.go:16
package model
import (
"errors"
"io"
"os"
"path/filepath"
"strings"
"github.com/siyuan-note/siyuan/kernel/util"
)
// openTemplatePath 将绝对或相对路径限制在模板根目录内,文件操作通过根目录句柄防止符号链接越界。
func openTemplatePath(p string) (*os.Root, string, error) {
if p == "" {
return nil, "", errors.New("path is required")
}
base, err := filepath.Abs(filepath.Join(util.DataDir, "templates"))
if err != nil {
return nil, "", err
}
abs := p
if !filepath.IsAbs(abs) {
abs = filepath.Join(base, p)
}
rel, err := filepath.Rel(base, abs)
if err != nil || rel == "." || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
return nil, "", errors.New("template path is outside templates directory")
}
root, err := os.OpenRoot(base)
return root, rel, err
}
// ReadTemplateFile 在模板根目录内读取普通文件,禁止通过符号链接读取目录外的数据。View on GitHub (pinned to 9f775e8a12)