• Wraps a synchronous operation with automatic group management. Automatically calls startGroup() before the operation and endGroup() after. Ensures cleanup even if the operation throws an error.

    Type Parameters

    • T

      The return type of the wrapped function.

    Parameters

    • label: string

      The group label for this operation.

    • fn: () => T

      The synchronous function to wrap.

    • collapsed: boolean = true

      If true, creates a collapsed group (default: true).

    Returns T

    The return value of the wrapped function.

    Rethrows any error thrown by the wrapped function.

    export function withGroup<T>(label: string, fn: () => T, collapsed = true): T {
    startGroup(label, collapsed);
    try {
    return fn();
    } finally {
    endGroup();
    }
    }