Skip to content

Commit

Permalink
fix: console shows stack traces with outdated code (#6630)
Browse files Browse the repository at this point in the history
Fixes #6228 

## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
eladcon committed Jun 3, 2024
1 parent 2429488 commit 25f6c93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const formatWingError = async (error: unknown, entryPoint?: string) => {
output.push(
await prettyPrintError(error.causedBy, {
sourceEntrypoint: resolve(entryPoint ?? "."),
resetCache: true,
}),
);

Expand Down Expand Up @@ -107,7 +108,7 @@ export const formatWingError = async (error: unknown, entryPoint?: string) => {
};

export const formatTraceError = async (error: string): Promise<string> => {
let output = await prettyPrintError(error);
let output = await prettyPrintError(error, { resetCache: true });

// Remove ANSI color codes
const regex =
Expand Down
9 changes: 9 additions & 0 deletions libs/wingsdk/src/util/enhanced-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export interface PrettyPrintErrorOptions {
* If provided, ANSI color and format will be used.
*/
chalk?: typeof Chalk;

/**
* If true, will force reload all sources.
*/
resetCache?: boolean;
}

/**
Expand All @@ -36,6 +41,10 @@ export async function prettyPrintError(
const fBold = (s: string) => (chalk ? chalk.bold(s) : s);
const fDim = (s: string) => (chalk ? chalk.dim(s) : s);

if (options?.resetCache) {
StackTracey.resetCache();
}

let st: StackTracey | undefined;
let originalMessage = "";
if (typeof error === "string") {
Expand Down

0 comments on commit 25f6c93

Please sign in to comment.