siyuan-note/siyuan · error
ErrSYTargetNotebookRequired
ErrSYTargetNotebookRequired
Error message
target notebook required
What it means
ErrSYTargetNotebookRequired is a sentinel error returned by importSY0 when autoDetect mode is on, notebook creation is disabled, and no target notebook (boxID) was supplied. ImportSYAuto is designed to figure out the import destination itself, but without either an explicit notebook, permission to create one, or auto-detection succeeding, there is no valid destination, so the caller (api/import.go) can check errors.Is(err, model.ErrSYTargetNotebookRequired) and fall back to staging the import for user selection.
Solutions
- Supply a valid target notebook ID in the import request's "notebook" field
- If the destination should be a new notebook, use the import variant that creates a notebook (ImportSYNotebook)
- Treat this sentinel as a control-flow signal: stage the import (as api/import.go does with stageSYImport) and let the user choose the destination
- Validate the request body (notebook non-empty or notebook-creation enabled) before calling the API
Example fix
// before
fetchPost("/api/import/importSY", {"path": zipPath})
// after
fetchPost("/api/import/importSY", {"path": zipPath, "notebook": "20240101120000-abc"}) Defensive patterns
Strategy: validation
Validate before calling
if (!request.notebook && !allowCreateNotebook) { throw new Error("target notebook required"); } Try / catch
createdBoxID, notebook, err := model.ImportSYAuto(path, reqNotebook, toPath); if errors.Is(err, model.ErrSYTargetNotebookRequired) { // stage the import and prompt the user for a destination } Prevention
- Always send the "notebook" field for document-tree import requests
- Use the staged-import fallback when the destination should be user-selected
- Validate request bodies at the API client layer before calling import
When it happens
Trigger: POST to the import API (model.ImportSYAuto) with request.Notebook == "" and a payload that is not a notebook bundle, so autoDetect cannot create a notebook (createNotebook false) and boxID is empty.
Common situations: API clients omitting the "notebook" field in the import request body while sending a document-tree zip; frontends that rely on the staged-import fallback flow triggering the error intentionally.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- 199
- AI editor action must not be empty
- block [ ] type is locked: expected , got
- block swap requires two non-document blocks
- Bookmark cannot be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/2f50863e7abc02bc.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/import.go:168
}
return ast.WalkContinue
})
return
}
func ImportSY(zipPath, boxID, toPath string) (err error) {
if isSYNotebookBundle(zipPath) {
return errors.New(Conf.Language(373))
}
_, err = importSY(zipPath, boxID, toPath, false, false)
return
}
func ImportSYNotebook(zipPath string) (boxID string, err error) {
return importSY(zipPath, "", "/", true, false)
}
var ErrSYTargetNotebookRequired = errors.New("target notebook required")
func ImportSYAuto(zipPath, boxID, toPath string) (createdBoxID string, notebook bool, err error) {
createdBoxID, err = importSY(zipPath, boxID, toPath, false, true)
notebook = err == nil && createdBoxID != boxID
return
}
func isSYNotebookExport(hasBoxConf, hasBoxDocMeta bool) bool {
return hasBoxConf || hasBoxDocMeta
}
type importedSYSortDoc struct {
oldID string
newID string
sourcePath string
hidden bool
}
View on GitHub (pinned to 9f775e8a12)