From 3b280589c2aa26f20fbef21fe0dd1a28cd8e0f9e Mon Sep 17 00:00:00 2001 From: Alexis Delrieu Date: Sat, 14 Feb 2026 04:44:50 +0100 Subject: [PATCH] enh: replace generic error with TokenNotFoundError in findRunElementIndexWithToken (#3309) Co-authored-by: Dolan --- src/patcher/paragraph-split-inject.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/patcher/paragraph-split-inject.ts b/src/patcher/paragraph-split-inject.ts index c3033732cd..28aa12621d 100644 --- a/src/patcher/paragraph-split-inject.ts +++ b/src/patcher/paragraph-split-inject.ts @@ -2,6 +2,13 @@ import { Element } from "xml-js"; import { createTextElementContents, patchSpaceAttribute } from "./util"; +export class TokenNotFoundError extends Error { + public constructor(token: string) { + super(`Token ${token} not found`); + this.name = "TokenNotFoundError"; + } +} + export const findRunElementIndexWithToken = (paragraphElement: Element, token: string): number => { for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) { const element = paragraphElement.elements![i]; @@ -20,7 +27,7 @@ export const findRunElementIndexWithToken = (paragraphElement: Element, token: s } } - throw new Error("Token not found"); + throw new TokenNotFoundError(token); }; export const splitRunElement = (runElement: Element, token: string): { readonly left: Element; readonly right: Element } => {