enh: replace generic error with TokenNotFoundError in findRunElementIndexWithToken (#3309)

Co-authored-by: Dolan <dolan_miu@hotmail.com>
This commit is contained in:
Alexis Delrieu
2026-02-14 03:44:50 +00:00
committed by GitHub
co-authored by Dolan
parent 65e904a83b
commit 3b280589c2
+8 -1
View File
@@ -2,6 +2,13 @@ import { Element } from "xml-js";
import { createTextElementContents, patchSpaceAttribute } from "./util"; 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 => { export const findRunElementIndexWithToken = (paragraphElement: Element, token: string): number => {
for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) { for (let i = 0; i < (paragraphElement.elements ?? []).length; i++) {
const element = paragraphElement.elements![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 } => { export const splitRunElement = (runElement: Element, token: string): { readonly left: Element; readonly right: Element } => {