diff options
| author | ST-DDT <[email protected]> | 2024-09-10 00:56:58 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-09 22:56:58 +0000 |
| commit | acb8b5258fa645e499831fca43b319b0439c0baf (patch) | |
| tree | 249085a072923558c7cacc9a276c16a11697f617 /scripts/apidocs/processing/error.ts | |
| parent | f128d77194003192d27a3eb897f4a7ad02980ed0 (diff) | |
| download | faker-acb8b5258fa645e499831fca43b319b0439c0baf.tar.xz faker-acb8b5258fa645e499831fca43b319b0439c0baf.zip | |
infra: improve error messages for parameter properties (#3082)
Diffstat (limited to 'scripts/apidocs/processing/error.ts')
| -rw-r--r-- | scripts/apidocs/processing/error.ts | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/scripts/apidocs/processing/error.ts b/scripts/apidocs/processing/error.ts index f171d6b4..e4117301 100644 --- a/scripts/apidocs/processing/error.ts +++ b/scripts/apidocs/processing/error.ts @@ -1,4 +1,5 @@ import { FakerError } from '../../../src/errors/faker-error'; +import { CI_PREFLIGHT } from '../../env'; import type { SourceableNode } from './source'; import { getSourcePath } from './source'; @@ -6,14 +7,22 @@ export class FakerApiDocsProcessingError extends FakerError { constructor(options: { type: string; name: string; - source: string | SourceableNode; + source: SourceableNode; cause: unknown; }) { const { type, name, source, cause } = options; - const sourceText = - typeof source === 'string' ? source : getSourcePathText(source); + + const mainText = `Failed to process ${type} '${name}'`; const causeText = cause instanceof Error ? cause.message : ''; - super(`Failed to process ${type} ${name} at ${sourceText} : ${causeText}`, { + const { filePath, line, column } = getSourcePath(source); + const sourceText = `${filePath}:${line}:${column}`; + + if (CI_PREFLIGHT) { + const sourceArgs = `file=${filePath},line=${line},col=${column}`; + console.log(`::error ${sourceArgs}::${mainText}: ${causeText}`); + } + + super(`${mainText} at ${sourceText} : ${causeText}`, { cause, }); } @@ -22,7 +31,7 @@ export class FakerApiDocsProcessingError extends FakerError { export function newProcessingError(options: { type: string; name: string; - source: string | SourceableNode; + source: SourceableNode; cause: unknown; }): FakerApiDocsProcessingError { const { cause } = options; @@ -33,8 +42,3 @@ export function newProcessingError(options: { return new FakerApiDocsProcessingError(options); } - -function getSourcePathText(source: SourceableNode): string { - const { filePath, line, column } = getSourcePath(source); - return `${filePath}:${line}:${column}`; -} |
