[Bug] app.workspace.getLeaf(true) throws an error: "Error: No tab group found."

The things is: I want to develop a workspace plugin.
use the code for clearing all leaves:

function clearAllLeavies(app: App) {
const { workspace } = app;
const allLeaf = new Set();

workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => {
	const { type } = leaf.getViewState();

	// if (type !== "empty")
	allLeaf.add(leaf.getViewState().type);
});

// console.log("all leveas type: %o", allLeaf);
allLeaf.forEach(leaf => {
	workspace.detachLeavesOfType(leaf);
});

}

And then the rootSplit becomes :
|main[split - vertical] [8925fe72c5efd0b2]|

There’re not any nodes in it.

I want to create a “tab” node in rootSplit by app.workspace.getLeaf(true) ,
but get an error :
image

Sorry for my poor English.
Any help would be greatly appreciated .
Thanks.