From f742ddb554beea680a0c3684c075dc5915dbb0e9 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 20 Sep 2023 20:56:55 +0100 Subject: [PATCH] refactor: rename renderStack to renderError BREAKING CHANGE: renderStack is now renderError --- source/render.ts | 21 ++++++++++++--------- spec/render.spec.ts | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/source/render.ts b/source/render.ts index 5224361..7e3aff7 100644 --- a/source/render.ts +++ b/source/render.ts @@ -24,6 +24,14 @@ import { disassembleStack } from './stack'; import type { StackDescriptionBlock, StackLocationBlock } from './stack'; +/** options for rendering an error */ +export interface RenderErrorOptions { + /** indicate whether a source frame should be shown */ + showSource?: boolean; + /** a filter function determining whether a stack should be shown given the file path */ + filter?: (path: string) => boolean; +} + /** default number of lines from the targeted source line to be displayed */ const DEFAULT_SPREAD = 4; @@ -49,19 +57,14 @@ const DEFAULT_YAML_THEME = { }; /** - * render a highly readable error stack + * render an error in a human readable format * @param error the error to be rendered * @param options optional parameters - * @param options.showSource indicate whether a source frame should be shown - * @param options.filter a filter determining whether a stack should be shown given the file path - * @returns a rendered string to print + * @returns a string representation of the error */ -export function renderStack( +export function renderError( error: Error, - options?: { - showSource?: boolean; - filter?: (path: string) => boolean; - }, + options?: RenderErrorOptions, ): string { const { showSource = false, diff --git a/spec/render.spec.ts b/spec/render.spec.ts index 26e62b7..29d7170 100644 --- a/spec/render.spec.ts +++ b/spec/render.spec.ts @@ -55,8 +55,8 @@ class MockedError extends Error { } } -const { renderStack } = await import('#render'); -describe('fn:renderStack', () => { +const { renderError: renderStack } = await import('#render'); +describe('fn:renderError', () => { it('should render an error stack with its own format', () => { const rendered = renderStack( new MockedError(