From b1005227ab85cf3ba0548116df3dfb49432b54b6 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 16 Oct 2024 19:52:47 -0400 Subject: [PATCH] Added PathError for easy detection --- package.json | 2 +- src/path-events.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 59067d0..26c3724 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.20.7", + "version": "0.20.8", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/path-events.ts b/src/path-events.ts index 3bc61a1..37eb55b 100644 --- a/src/path-events.ts +++ b/src/path-events.ts @@ -52,6 +52,8 @@ export function PES(str: TemplateStringsArray, ...args: any[]) { return PathEvent.toString(paths, methods?.split('')); } +export class PathError extends Error { } + /** * A event broken down into its core components for easy processing * Event Structure: `module/path/name:property:method` @@ -172,7 +174,7 @@ export class PathEvent { * @param has Target must have at least one of these path */ static hasFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void { - if(!PathEvent.has(target, ...has)) throw new Error(`Requires one of: ${makeArray(has).join(', ')}`); + if(!PathEvent.has(target, ...has)) throw new PathError(`Requires one of: ${makeArray(has).join(', ')}`); } /** @@ -182,7 +184,7 @@ export class PathEvent { * @param has Target must have all these paths */ static hasAllFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void { - if(!PathEvent.hasAll(target, ...has)) throw new Error(`Requires all: ${makeArray(has).join(', ')}`); + if(!PathEvent.hasAll(target, ...has)) throw new PathError(`Requires all: ${makeArray(has).join(', ')}`); } /**