# code-block-pro/1.27.7/src/util/errors.ts

Code Block Pro – Beautiful Syntax Highlighting, version 1.27.7. 46 lines.

- Page: https://pluginprobe.com/plugins/code-block-pro/1.27.7/code/src/util/errors.ts
- Raw: https://pluginprobe.com/plugins/code-block-pro/1.27.7/raw/src/util/errors.ts
- Modified: 2025-07-05T14:10:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/code-block-pro/1.27.7/code/src/util/errors.ts#L10-L20`.

```typescript
import { subscribe } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

export const debounce = <T extends (...args: unknown[]) => void>(
    fn: T,
    delay: number,
) => {
    let timeout: ReturnType<typeof setTimeout> | null = null;
    return (...args: Parameters<T>) => {
        if (timeout) clearTimeout(timeout);
        timeout = setTimeout(() => fn(...args), delay);
    };
};

export const handleValidationErrors = () => {
    const debouncedUnsub = debounce(() => unsub(), 5000);

    const unsub = subscribe(() => {
        const editor = document.querySelector(
            '#editor, iframe[name="editor-canvas"]',
        );
        const blockErrors = editor?.querySelectorAll(
            '.wp-block-kevinbatdorf-code-block-pro .block-editor-warning',
        );
        if (!blockErrors?.length) return;
        blockErrors.forEach((blockError) => {
            const message = blockError.querySelector(
                '.block-editor-warning__message',
            );
            if (message) {
                message.textContent = __(
                    'This block has been updated. Press update to refresh.',
                    'code-block-pro',
                );
            }
            const button = blockError.querySelector(
                '.block-editor-warning__action button',
            );
            if (button) {
                button.textContent = __('Update', 'code-block-pro');
            }
        });
        debouncedUnsub();
    });
};

```
