aboutsummaryrefslogtreecommitdiff
path: root/scripts/apidocs/processing/error.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-04-01 10:21:18 +0200
committerGitHub <[email protected]>2024-04-01 10:21:18 +0200
commit6191a5d883048b694404dbf42527caba395828ea (patch)
treed0f18f17789cb0bbdb5d6087f1a95772438dfe27 /scripts/apidocs/processing/error.ts
parent7dae52bfcd93c41ec9d2c4dd4d96a07f31c3dfc1 (diff)
downloadfaker-6191a5d883048b694404dbf42527caba395828ea.tar.xz
faker-6191a5d883048b694404dbf42527caba395828ea.zip
docs: rewrite api-docs generation using ts-morph (#2628)
Diffstat (limited to 'scripts/apidocs/processing/error.ts')
-rw-r--r--scripts/apidocs/processing/error.ts40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/apidocs/processing/error.ts b/scripts/apidocs/processing/error.ts
new file mode 100644
index 00000000..f171d6b4
--- /dev/null
+++ b/scripts/apidocs/processing/error.ts
@@ -0,0 +1,40 @@
+import { FakerError } from '../../../src/errors/faker-error';
+import type { SourceableNode } from './source';
+import { getSourcePath } from './source';
+
+export class FakerApiDocsProcessingError extends FakerError {
+ constructor(options: {
+ type: string;
+ name: string;
+ source: string | SourceableNode;
+ cause: unknown;
+ }) {
+ const { type, name, source, cause } = options;
+ const sourceText =
+ typeof source === 'string' ? source : getSourcePathText(source);
+ const causeText = cause instanceof Error ? cause.message : '';
+ super(`Failed to process ${type} ${name} at ${sourceText} : ${causeText}`, {
+ cause,
+ });
+ }
+}
+
+export function newProcessingError(options: {
+ type: string;
+ name: string;
+ source: string | SourceableNode;
+ cause: unknown;
+}): FakerApiDocsProcessingError {
+ const { cause } = options;
+
+ if (cause instanceof FakerApiDocsProcessingError) {
+ return cause;
+ }
+
+ return new FakerApiDocsProcessingError(options);
+}
+
+function getSourcePathText(source: SourceableNode): string {
+ const { filePath, line, column } = getSourcePath(source);
+ return `${filePath}:${line}:${column}`;
+}