{"record":{"id":"9860effc170a3a0e","repo":"siyuan-note/siyuan","slug":"create-import-dir-failed-s","errorCode":null,"errorMessage":"create import dir failed: %s","messagePattern":"create import dir failed: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":363,"sourceCode":"\tmaxReadBytes := int64(maxHTTPRequestBytes)\n\tif !isTextContentType(contentType) {\n\t\tmaxReadBytes = maxHTTPRequestFileBytes\n\t}\n\t// ContentLength 为 -1（chunked）时跳过大小预检，交由 LimitReader 兜底截断。\n\tif resp.ContentLength > maxReadBytes {\n\t\treturn statusCode, contentType, \"\", errors.New(\"response too large\")\n\t}\n\n\trespBody, rerr := io.ReadAll(io.LimitReader(resp.Body, maxReadBytes))\n\tif rerr != nil {\n\t\treturn statusCode, contentType, \"\", errors.New(\"read body failed: \" + rerr.Error())\n\t}\n\n\t// 二进制响应落盘，返回文件路径，供智能体按需进一步处理。\n\tif !isTextContentType(contentType) {\n\t\timportDir := filepath.Join(TempDir, \"import\")\n\t\tif merr := os.MkdirAll(importDir, 0755); merr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"create import dir failed: \" + merr.Error())\n\t\t}\n\t\tfilename := extractFilename(rawURL, contentType)\n\t\tfilePath := filepath.Join(importDir, filename)\n\t\tif werr := os.WriteFile(filePath, respBody, 0644); werr != nil {\n\t\t\treturn statusCode, contentType, \"\", errors.New(\"write file failed: \" + werr.Error())\n\t\t}\n\t\treturn statusCode, contentType, fmt.Sprintf(\"Saved to: %s (%d bytes)\", filePath, len(respBody)), nil\n\t}\n\n\treturn statusCode, contentType, truncateRunes(string(respBody), maxHTTPRequestChars), nil\n}\n\n// isTextContentType 判断 Content-Type 是否为可直接展示给智能体的文本类响应。\n// 覆盖 text/*、application/json、application/xml、application/*+json 等。\nfunc isTextContentType(contentType string) bool {\n\tct := strings.ToLower(strings.TrimSpace(strings.SplitN(contentType, \";\", 2)[0]))\n\tif ct == \"\" {\n\t\treturn false","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/util/httprequest.go#L345-L381","documentation":"Binary responses are saved to disk under <workspace temp>/import before being reported to the agent, and os.MkdirAll failed while creating that directory. The suffix carries the OS error - typically permission denied, no space left on device, or a read-only filesystem. TempDir is the kernel workspace temp directory, set during boot.","triggerScenarios":"Downloading a binary (image, zip, etc.) via util.HTTPRequest while the workspace temp directory is on a full disk, has restrictive ownership/permissions, sits on a read-only mount, or TempDir was never initialized in an unusual embedded/mobile context.","commonSituations":"Docker containers with a small tmpfs or full volume; workspace moved or restored with wrong ownership; disk quota exceeded; sandboxed environments where the kernel workspace is read-only.","solutions":["Free space or raise the quota on the volume holding the SiYuan workspace temp directory","Fix ownership/permissions so the kernel process can create directories under the temp dir","Ensure the kernel went through normal boot so TempDir is set; restart after fixing the filesystem","Retry the download once the filesystem issue is resolved"],"exampleFix":"// before: binary download attempted with unwritable temp dir\nutil.HTTPRequest(\"GET\", \"https://cdn.example.com/logo.png\", nil, \"\")\n\n// after: verify the import dir is writable before triggering binary downloads\nimportDir := filepath.Join(util.TempDir, \"import\")\nif probe, perr := os.CreateTemp(importDir, \"probe-*\"); perr != nil {\n    return perr // fix disk/permissions first\n} else {\n    probe.Close()\n    os.Remove(probe.Name())\n}","handlingStrategy":"try-catch","validationCode":"importDir := filepath.Join(util.TempDir, \"import\")\nif perr := os.MkdirAll(importDir, 0755); perr != nil {\n    return fmt.Errorf(\"temp import dir unavailable: %w\", perr)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create import dir failed\") {\n    // filesystem problem (space/permissions): report to the user; retrying the download cannot fix it\n}","preventionTips":["Monitor free space on the volume hosting the workspace temp directory","Ensure the kernel process owns or can write to its temp directory","Never mount the workspace temp dir read-only in containers that run agent tools"],"tags":["filesystem","disk","temp-dir","agent-tools"],"backgroundTag":"directory-creation-failed","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}