Skip to content

Commit

Permalink
fix(AnWeber/vscode-httpyac#338): do not log stack on assertions error
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Nov 3, 2024
1 parent 55e0867 commit e8851dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/utils/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { log } from '../io';
import * as models from '../models';
import { toBoolean, toNumber } from './convertUtils';
import { parseMimeType } from './mimeTypeUtils';
import { isString, toMultiLineString } from './stringUtils';
import { isString, toMultiLineArray, toMultiLineString } from './stringUtils';

export function isHttpRequestMethod(method: string | undefined): method is models.HttpMethod {
if (method) {
Expand Down Expand Up @@ -274,6 +274,15 @@ export function requestLoggerFactory(
} else if ([models.TestResultStatus.ERROR, models.TestResultStatus.FAILED].includes(testResult.status)) {
const errorMessage = testResult.error ? ` (${testResult.error?.displayMessage})` : '';
message = chalk`{red ${models.testSymbols.error} ${testResult.message || 'Test failed'}${errorMessage}}`;

if (
!options?.useShort &&
testResult.status === models.TestResultStatus.ERROR &&
testResult.error?.error.stack
) {
const linesOfStack = toMultiLineArray(testResult.error.error.stack).slice(0, 3);
message = toMultiLineString([message, ...linesOfStack]);
}
}
log(message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function testFactoryAsync(
try {
await testMethod(testResult);
} catch (err) {
setErrorInTestResult(testResult, err);
setErrorInTestResult(testResult, err, TestResultStatus.ERROR);
if (options.ignoreErrorFile && testResult.error?.errorType) {
testResult.error.displayMessage = `${testResult.error.errorType}: ${testResult.error.message}`;
}
Expand All @@ -41,8 +41,8 @@ export function testFactoryAsync(
};
}

function setErrorInTestResult(testResult: TestResult, err: unknown) {
testResult.status = TestResultStatus.FAILED;
function setErrorInTestResult(testResult: TestResult, err: unknown, status = TestResultStatus.FAILED) {
testResult.status = status;
if (isError(err)) {
testResult.error = parseError(err);
} else {
Expand Down

0 comments on commit e8851dc

Please sign in to comment.