siyuan-note/siyuan · error

marshal workspace conf [%s] failed: %s

Error message

marshal workspace conf [%s] failed: %s

What it means

WriteWorkspacePaths persists the list of workspace directories to ~/.config/siyuan/workspace.json via gulu.JSON.MarshalJSON. This error means marshaling that slice to JSON failed, which is practically impossible for a []string and indicates an internal serialization fault. The original error is logged then wrapped in a new generic error, losing the %w chain.

Source

Thrown at kernel/util/working.go:456

		if gulu.File.IsDir(d) {
			tmp = append(tmp, d)
		} else {
			logging.LogWarnf("workspace path [%s] is not a dir", d)
		}
	}
	ret = tmp
	ret = DeduplicateWorkspacePaths(ret)
	return
}

func WriteWorkspacePaths(workspacePaths []string) (err error) {
	workspacePaths = DeduplicateWorkspacePaths(workspacePaths)
	workspaceConf := filepath.Join(HomeDir, ".config", "siyuan", "workspace.json")
	data, err := gulu.JSON.MarshalJSON(workspacePaths)
	if err != nil {
		msg := fmt.Sprintf("marshal workspace conf [%s] failed: %s", workspaceConf, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	if err = filelock.WriteFile(workspaceConf, data); err != nil {
		msg := fmt.Sprintf("write workspace conf [%s] failed: %s", workspaceConf, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}
	return
}

var (
	ServerURL  *url.URL // 内核服务 URL
	ServerPort = "0"    // HTTP/WebSocket 端口,0 为使用随机端口

	ReadOnly       bool
	AccessAuthCode string

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Check the kernel log for the logged underlying marshal error from logging.LogError and fix per its message
  2. Update github.com/88250/gulu to the version pinned by kernel/go.mod (a stale vendored copy can break JSON encoding)
  3. Verify no fork/customization altered the type of the workspace-paths slice passed to WriteWorkspacePaths
  4. Confirm workspaceConf path (~/.config/siyuan/workspace.json) is only informational here; the failure is in-memory marshal, not disk write
Defensive patterns

Strategy: try-catch

Try / catch

// Go
if err := util.WriteWorkspacePaths(paths); err != nil {
    if strings.Contains(err.Error(), "marshal workspace conf") {
        // log and degrade: workspace list not persisted; app still runs
        return fmt.Errorf("workspace list not persisted: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling WriteWorkspacePaths (directly or via createWorkspaceDir, removeWorkspaceDir, removeWorkspaceDirPhysically, setWorkspaceDir, Close) when gulu.JSON.MarshalJSON returns an error on the deduplicated workspace-paths slice.

Common situations: Rare in practice; would require a defective/older gulu version whose reflection-based marshaler fails, or a non-standard type injected into the paths slice in a fork. Effectively signals a kernel-internal bug.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/0861d06e032a37e0. Report an issue: GitHub.