Skip to content

Commit

Permalink
refactor: rename renderStack to renderError
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renderStack is now renderError
  • Loading branch information
alvis committed Sep 20, 2023
1 parent 4964a4a commit f742ddb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions source/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions spec/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f742ddb

Please sign in to comment.