Skip to content

Commit a0a07d1

Browse files
test: Improve Failure Message
1 parent b188eac commit a0a07d1

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

__tests__/functional/e2e.functional.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('E2E Test Cases', () => {
119119
format: getImageFormat(filename),
120120
});
121121

122-
expect(response.error, `Classification error for ${filename}`).toBeNull();
122+
expect(response.error, `Classification error for ${filename}`).toBeUndefined();
123123

124124
// Build actual weights map
125125
const actualWeights = new Map<string, number>();

__tests__/functional/main.functional.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('ClassifierSdk Functional Tests', () => {
6464

6565
const response = await sdk.classifySingle(input);
6666
expect(Array.isArray(response.classifications)).toBe(true);
67-
expect(response.error).toBeNull();
67+
expect(response.error).toBeUndefined();
6868
}, 10000);
6969
});
7070

samples/e2e-testcases/index.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,46 @@ function compareResults(
233233
return differences;
234234
}
235235

236+
/**
237+
* Format structured SDK and runtime errors for readable CLI output.
238+
*/
239+
function formatError(error: unknown): string {
240+
if (error instanceof Error) {
241+
return error.message;
242+
}
243+
244+
if (typeof error === 'string') {
245+
return error;
246+
}
247+
248+
if (error && typeof error === 'object') {
249+
const details = error as {
250+
code?: unknown;
251+
message?: unknown;
252+
details?: unknown;
253+
};
254+
255+
const parts = [details.message, details.details]
256+
.filter((value): value is string => typeof value === 'string' && value.length > 0);
257+
258+
if (typeof details.code === 'number' || typeof details.code === 'string') {
259+
parts.unshift(`code ${details.code}`);
260+
}
261+
262+
if (parts.length > 0) {
263+
return parts.join(' - ');
264+
}
265+
266+
try {
267+
return JSON.stringify(error);
268+
} catch {
269+
return String(error);
270+
}
271+
}
272+
273+
return String(error);
274+
}
275+
236276
/**
237277
* Main execution
238278
*/
@@ -293,7 +333,9 @@ async function main(): Promise<void> {
293333
});
294334

295335
if (response.error) {
296-
console.error(` ✗ ${filename} - Classification error: ${response.error}`);
336+
console.error(
337+
` ✗ ${filename} - Classification error: ${formatError(response.error)}`,
338+
);
297339
results.push({ filename, passed: false, differences: [] });
298340
continue;
299341
}
@@ -323,7 +365,7 @@ async function main(): Promise<void> {
323365
}
324366
}
325367
} catch (error) {
326-
const message = error instanceof Error ? error.message : String(error);
368+
const message = formatError(error);
327369
console.error(` ✗ ${filename} - Error: ${message}`);
328370
results.push({ filename, passed: false, differences: [] });
329371
}

0 commit comments

Comments
 (0)