Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 05:45 UTC
fix: log transform validation failures as warnings with field details
Replace logger.error(zodError) with logger.warn() containing a human-readable message that lists each failing field path and its validation error. Remove the unused ValidationError import and the stale commented-out throw block. This makes validation failures visible at warn level with actionable context (field names + error messages), without breaking callers that depend on receiving the untransformed data. Fixes #2716
Ratnaditya-J committed
Feb 27, 2026 at 22:41 UTC
ac4ef5b616d9f6827017af0aaf195cc339d3b896
2 files changed
+119
-9
ts/packages/core/src/utils/transform.ts
+5
-9
@@ -12,7 +12,6 @@
12
* ```
13
*/
14
import { ZodTypeAny, z } from 'zod/v3';
15
-import { ValidationError } from '../errors';
15
import { logger } from '..';
16
17
export function transform<RawInput>(raw: RawInput) {
@@ -27,14 +26,11 @@ export function transform<RawInput>(raw: RawInput) {
26
const result = schema.safeParse(transformed);
27
28
if (!result.success) {
30
- // @TODO:send telemetry here
31
- // throw new ValidationError(
32
- // `Failed to transform${options?.label ? ` ${options.label}` : ''}`,
33
- // {
34
- // cause: result.error,
35
- // }
36
- // );
37
- logger.error(result.error);
29
+ const label = options?.label ? ` ${options.label}` : '';
30
+ const issues = result.error.issues
31
+ .map(issue => ` - ${issue.path.join('.')}: ${issue.message}`)
32
+ .join('\n');
33
+ logger.warn(`Transform validation failed${label}:\n${issues}`);
34
return transformed;
35
}
36
ts/packages/core/test/utils/transform.test.ts
new
+114
@@ -0,0 +1,114 @@
1
+import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+import { z } from 'zod/v3';
3
+
4
+const mockLogger = vi.hoisted(() => ({
5
+ warn: vi.fn(),
6
+ error: vi.fn(),
7
+ info: vi.fn(),
8
+ debug: vi.fn(),
9
+}));
10
+
11
+vi.mock('../../src/utils/logger', () => ({
12
+ default: mockLogger,
13
+}));
14
+
15
+vi.mock('../../src/index', () => ({
16
+ logger: mockLogger,
17
+}));
18
+
19
+import { transform } from '../../src/utils/transform';
20
+
21
+describe('transform', () => {
22
+ beforeEach(() => {
23
+ vi.clearAllMocks();
24
+ });
25
+
26
+ it('should return validated data when schema matches', () => {
27
+ const schema = z.object({
28
+ name: z.string(),
29
+ age: z.number(),
30
+ });
31
+
32
+ const result = transform({ raw_name: 'Alice', raw_age: 30 })
33
+ .with(schema)
34
+ .using(raw => ({ name: raw.raw_name, age: raw.raw_age }));
35
+
36
+ expect(result).toEqual({ name: 'Alice', age: 30 });
37
+ });
38
+
39
+ it('should strip extra fields via Zod parsing on valid data', () => {
40
+ const schema = z.object({
41
+ name: z.string(),
42
+ });
43
+
44
+ const result = transform({ name: 'Alice', extra: 'field' })
45
+ .with(schema)
46
+ .using(raw => raw as any);
47
+
48
+ expect(result).toEqual({ name: 'Alice' });
49
+ expect(result).not.toHaveProperty('extra');
50
+ });
51
+
52
+ it('should return untransformed data and log a warning on validation failure', () => {
53
+ const schema = z.object({
54
+ name: z.string(),
55
+ age: z.number(),
56
+ });
57
+
58
+ const result = transform({ name: 123, age: 'not a number' })
59
+ .with(schema)
60
+ .using(raw => raw as any);
61
+
62
+ expect(result).toEqual({ name: 123, age: 'not a number' });
63
+
64
+ expect(mockLogger.warn).toHaveBeenCalledTimes(1);
65
+ expect(mockLogger.error).not.toHaveBeenCalled();
66
+
67
+ const warnMessage = mockLogger.warn.mock.calls[0][0] as string;
68
+ expect(warnMessage).toContain('Transform validation failed');
69
+ expect(warnMessage).toContain('name');
70
+ expect(warnMessage).toContain('age');
71
+ });
72
+
73
+ it('should include label in the warning message when provided', () => {
74
+ const schema = z.object({ id: z.string() });
75
+
76
+ transform({ id: 42 })
77
+ .with(schema)
78
+ .using(raw => raw as any, { label: 'ConnectedAccount' });
79
+
80
+ expect(mockLogger.warn).toHaveBeenCalledTimes(1);
81
+ const warnMessage = mockLogger.warn.mock.calls[0][0] as string;
82
+ expect(warnMessage).toContain('ConnectedAccount');
83
+ });
84
+
85
+ it('should not log anything when validation succeeds', () => {
86
+ const schema = z.object({ id: z.string() });
87
+
88
+ const result = transform({ id: 'abc' })
89
+ .with(schema)
90
+ .using(raw => raw as any);
91
+
92
+ expect(result).toEqual({ id: 'abc' });
93
+ expect(mockLogger.warn).not.toHaveBeenCalled();
94
+ expect(mockLogger.error).not.toHaveBeenCalled();
95
+ });
96
+
97
+ it('should handle nested schema validation failures', () => {
98
+ const schema = z.object({
99
+ user: z.object({
100
+ email: z.string().email(),
101
+ }),
102
+ });
103
+
104
+ const result = transform({ user: { email: 'not-an-email' } })
105
+ .with(schema)
106
+ .using(raw => raw as any);
107
+
108
+ expect(result).toEqual({ user: { email: 'not-an-email' } });
109
+ expect(mockLogger.warn).toHaveBeenCalledTimes(1);
110
+
111
+ const warnMessage = mockLogger.warn.mock.calls[0][0] as string;
112
+ expect(warnMessage).toContain('user.email');
113
+ });
114
+});