{"record":{"id":"9913ea25bffaf817","repo":"siyuan-note/siyuan","slug":"create-inline-styles-directory-failed-w","errorCode":null,"errorMessage":"create inline styles directory failed: %w","messagePattern":"create inline styles directory failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":296,"sourceCode":"\tif err != nil {\n\t\treturn nil, false, fmt.Errorf(\"marshal inline styles failed: %w\", err)\n\t}\n\tif maxInlineStylesFileSize < len(data) {\n\t\treturn nil, false, fmt.Errorf(\"inline styles file exceeds the %d byte limit\", maxInlineStylesFileSize)\n\t}\n\n\tdataPath := inlineStylesPath()\n\toldData, readErr := filelock.ReadFile(dataPath)\n\tif readErr != nil && !os.IsNotExist(readErr) {\n\t\treturn nil, false, fmt.Errorf(\"read inline styles failed: %w\", readErr)\n\t}\n\tif bytes.Equal(oldData, data) {\n\t\tcacheWorkspaceAVPalette(ret.AV)\n\t\treturn ret, false, nil\n\t}\n\n\tif err = os.MkdirAll(filepath.Dir(dataPath), 0755); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"create inline styles directory failed: %w\", err)\n\t}\n\tif err = filelock.WriteFile(dataPath, data); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"write inline styles failed: %w\", err)\n\t}\n\tcacheWorkspaceAVPalette(ret.AV)\n\tIncSync()\n\tfor _, avID := range sortedAttributeViewUsageIDs(customColorUsage) {\n\t\tindexes := customColorUsage[avID]\n\t\tif intersectsCustomColorIndexes(indexes, changedCustomColorIndexes) {\n\t\t\tpushReloadAttrView(avID)\n\t\t}\n\t}\n\treturn ret, true, nil\n}\n\nfunc inlineStylesPath() string {\n\treturn filepath.Join(util.DataDir, \"storage\", \"inline-styles.json\")\n}","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L278-L314","documentation":"Before writing the new styles JSON, setInlineStylesData ensures the parent directory (under the workspace storage path) exists via os.MkdirAll. If directory creation fails (permissions, read-only FS, path is a file), the write aborts with this wrapped error.","triggerScenarios":"The target directory path exists as a regular file; the workspace volume is read-only or full; the process lacks write permission on the storage parent directory; SELinux/AppArmor denies creation.","commonSituations":"Docker containers with a read-only or mis-mounted workspace; a stray file named like the expected directory after a bad restore; running as non-root against a root-owned workspace.","solutions":["Check that filepath.Dir(inlineStylesPath()) is not occupied by a regular file; remove/rename the file","Grant the kernel process write permission on the workspace storage directory (chown/chmod)","Remount the workspace volume read-write if it is read-only","Inspect the wrapped OS error (permission denied vs no space vs not a directory) to target the fix"],"exampleFix":"# before\nstorage/inline_styles/  -> actually a regular file\n# after\nmv storage/inline_styles storage/inline_styles.bak && mkdir storage/inline_styles","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(stylesPath)\nif fi, err := os.Stat(dir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s is not a directory\", dir)\n}","typeGuard":null,"tryCatchPattern":"_, _, err := model.SetInlineStyles(styles)\nif err != nil && strings.HasPrefix(err.Error(), \"create inline styles directory failed\") {\n    return fmt.Errorf(\"check storage dir permissions/mount: %w\", err)\n}","preventionTips":["Ensure the workspace volume is mounted read-write before starting the kernel","Never place a regular file where the storage directory is expected","Pre-provision the storage directory with correct ownership in container images"],"tags":["go","filesystem","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}