siyuan-note/siyuan · error
create import dir failed:
Error message
create import dir failed:
What it means
When HTTPRequest receives a non-text response (binary content), it writes the body into <TempDir>/import. Before writing, it creates that directory with os.MkdirAll(importDir, 0755); if directory creation fails, the error is wrapped as "create import dir failed: <cause>". This is a local filesystem failure, not an HTTP problem.
Source
Thrown at kernel/util/httprequest.go:363
maxReadBytes := int64(maxHTTPRequestBytes)
if !isTextContentType(contentType) {
maxReadBytes = maxHTTPRequestFileBytes
}
// ContentLength 为 -1(chunked)时跳过大小预检,交由 LimitReader 兜底截断。
if resp.ContentLength > maxReadBytes {
return statusCode, contentType, "", errors.New("response too large")
}
respBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))
if rerr != nil {
return statusCode, contentType, "", errors.New("read body failed: " + rerr.Error())
}
// 二进制响应落盘,返回文件路径,供智能体按需进一步处理。
if !isTextContentType(contentType) {
importDir := filepath.Join(TempDir, "import")
if merr := os.MkdirAll(importDir, 0755); merr != nil {
return statusCode, contentType, "", errors.New("create import dir failed: " + merr.Error())
}
filename := extractFilename(rawURL, contentType)
filePath := filepath.Join(importDir, filename)
if werr := os.WriteFile(filePath, respBody, 0644); werr != nil {
return statusCode, contentType, "", errors.New("write file failed: " + werr.Error())
}
return statusCode, contentType, fmt.Sprintf("Saved to: %s (%d bytes)", filePath, len(respBody)), nil
}
return statusCode, contentType, truncateRunes(string(respBody), maxHTTPRequestChars), nil
}
// isTextContentType 判断 Content-Type 是否为可直接展示给智能体的文本类响应。
// 覆盖 text/*、application/json、application/xml、application/*+json 等。
func isTextContentType(contentType string) bool {
ct := strings.ToLower(strings.TrimSpace(strings.SplitN(contentType, ";", 2)[0]))
if ct == "" {
return falseView on GitHub (pinned to 8641553a1f)
Solutions
- Check the wrapped cause after the prefix: permission denied vs no space left vs not a directory, and fix accordingly
- Verify the workspace temp directory exists and is writable by the SiYuan process user (check disk space with df, permissions with ls -ld)
- If <TempDir>/import exists as a regular file, remove or rename it so MkdirAll can create the directory
- On sandboxed/managed systems, grant the process write access to its temp directory or relocate the workspace to a writable volume
Example fix
// diagnosis example $ ls -ld <workspace>/temp // if 'import' is a file: $ mv <workspace>/temp/import <workspace>/temp/import.bak $ mkdir <workspace>/temp/import
Defensive patterns
Strategy: validation
Validate before calling
importDir := filepath.Join(util.TempDir, "import")
if info, err := os.Stat(importDir); err == nil && !info.IsDir() {
return errors.New("import path exists but is not a directory")
}
if err := os.MkdirAll(importDir, 0755); err != nil {
return fmt.Errorf("temp dir not writable: %w", err)
} Try / catch
status, ct, text, err := util.HTTPRequest("GET", binaryURL, nil, "")
if err != nil && strings.Contains(err.Error(), "create import dir failed") {
// check disk space and permissions on the workspace temp dir before retrying
return fmt.Errorf("local storage problem, not HTTP: %w", err)
} Prevention
- Ensure the workspace volume has free space and the process user owns/holds write permission on the temp directory
- Check that <TempDir>/import is a directory, not a stale regular file
- On sandboxed systems, confirm the temp path is inside the writable sandbox
When it happens
Trigger: HTTPRequest() with a binary Content-Type response while os.MkdirAll on <TempDir>/import fails — read-only filesystem, full disk, permission denied on the temp directory, or TempDir pointing at a path that exists as a regular file.
Common situations: Running SiYuan with a read-only or full workspace/temp volume, restrictive umask or sandboxed environments where the temp directory is not writable, or a corrupted workspace where 'import' exists as a file.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- create inline styles directory failed: %w
- read session file failed: %w
- create session dir failed: %w
- create AI editor actions directory failed: %w
- mkdir box conf dir failed: %w
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/4000de52346a6849.
Report an issue: GitHub.