@sqaoss/flowy 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,4 +45,69 @@ describe('outputError', () => {
45
45
 
46
46
  expect(exitSpy).toHaveBeenCalledWith(1)
47
47
  })
48
+
49
+ test('exits 1 for VALIDATION_ERROR (usage/validation class)', () => {
50
+ vi.spyOn(console, 'error').mockImplementation(() => {})
51
+ const exitSpy = vi
52
+ .spyOn(process, 'exit')
53
+ .mockImplementation(() => undefined as never)
54
+
55
+ outputError(
56
+ Object.assign(new Error('bad input'), { code: 'VALIDATION_ERROR' }),
57
+ )
58
+
59
+ expect(exitSpy).toHaveBeenCalledWith(1)
60
+ })
61
+
62
+ test('exits 1 for CONFLICT (usage/validation class)', () => {
63
+ vi.spyOn(console, 'error').mockImplementation(() => {})
64
+ const exitSpy = vi
65
+ .spyOn(process, 'exit')
66
+ .mockImplementation(() => undefined as never)
67
+
68
+ outputError(Object.assign(new Error('conflict'), { code: 'CONFLICT' }))
69
+
70
+ expect(exitSpy).toHaveBeenCalledWith(1)
71
+ })
72
+
73
+ test('exits 2 for NOT_FOUND', () => {
74
+ vi.spyOn(console, 'error').mockImplementation(() => {})
75
+ const exitSpy = vi
76
+ .spyOn(process, 'exit')
77
+ .mockImplementation(() => undefined as never)
78
+
79
+ outputError(
80
+ Object.assign(new Error('Node bad-id not found'), { code: 'NOT_FOUND' }),
81
+ )
82
+
83
+ expect(exitSpy).toHaveBeenCalledWith(2)
84
+ })
85
+
86
+ test('exits 3 for SERVER_ERROR', () => {
87
+ vi.spyOn(console, 'error').mockImplementation(() => {})
88
+ const exitSpy = vi
89
+ .spyOn(process, 'exit')
90
+ .mockImplementation(() => undefined as never)
91
+
92
+ outputError(
93
+ Object.assign(new Error('Server returned HTTP 502'), {
94
+ code: 'SERVER_ERROR',
95
+ }),
96
+ )
97
+
98
+ expect(exitSpy).toHaveBeenCalledWith(3)
99
+ })
100
+
101
+ test('exits 4 for NETWORK_ERROR', () => {
102
+ vi.spyOn(console, 'error').mockImplementation(() => {})
103
+ const exitSpy = vi
104
+ .spyOn(process, 'exit')
105
+ .mockImplementation(() => undefined as never)
106
+
107
+ outputError(
108
+ Object.assign(new Error('Request timed out'), { code: 'NETWORK_ERROR' }),
109
+ )
110
+
111
+ expect(exitSpy).toHaveBeenCalledWith(4)
112
+ })
48
113
  })
@@ -2,6 +2,27 @@ export function output(data: unknown): void {
2
2
  console.log(JSON.stringify(data, null, 2))
3
3
  }
4
4
 
5
+ /**
6
+ * Map a GraphQL `extensions.code` (or transport code) to a distinct process
7
+ * exit code so callers can branch on failure class:
8
+ * 1 — usage / validation / conflict (default)
9
+ * 2 — not found
10
+ * 3 — server error (non-2xx, masked, non-JSON)
11
+ * 4 — network / transport (timeout, connection failure)
12
+ */
13
+ function exitCodeFor(code: string | undefined): number {
14
+ switch (code) {
15
+ case 'NOT_FOUND':
16
+ return 2
17
+ case 'SERVER_ERROR':
18
+ return 3
19
+ case 'NETWORK_ERROR':
20
+ return 4
21
+ default:
22
+ return 1
23
+ }
24
+ }
25
+
5
26
  export function outputError(error: unknown): void {
6
27
  const message = error instanceof Error ? error.message : String(error)
7
28
  const rawCode =
@@ -10,5 +31,5 @@ export function outputError(error: unknown): void {
10
31
  console.error(
11
32
  JSON.stringify(code ? { error: message, code } : { error: message }),
12
33
  )
13
- process.exit(1)
34
+ process.exit(exitCodeFor(code))
14
35
  }