@shopify/cli-kit 4.8.4 → 4.9.0

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.
Files changed (147) hide show
  1. package/dist/private/node/analytics.js +5 -3
  2. package/dist/private/node/analytics.js.map +1 -1
  3. package/dist/private/node/api/status-checks.d.ts +7 -0
  4. package/dist/private/node/api/status-checks.js +11 -0
  5. package/dist/private/node/api/status-checks.js.map +1 -0
  6. package/dist/private/node/api.d.ts +15 -0
  7. package/dist/private/node/api.js +28 -0
  8. package/dist/private/node/api.js.map +1 -1
  9. package/dist/private/node/command-event-context.d.ts +29 -0
  10. package/dist/private/node/command-event-context.js +43 -0
  11. package/dist/private/node/command-event-context.js.map +1 -0
  12. package/dist/private/node/command-event-output.d.ts +7 -0
  13. package/dist/private/node/command-event-output.js +16 -0
  14. package/dist/private/node/command-event-output.js.map +1 -0
  15. package/dist/private/node/command-json-schema.d.ts +10 -0
  16. package/dist/private/node/command-json-schema.js +38 -0
  17. package/dist/private/node/command-json-schema.js.map +1 -0
  18. package/dist/private/node/context/agent.d.ts +1 -0
  19. package/dist/private/node/context/agent.js +44 -0
  20. package/dist/private/node/context/agent.js.map +1 -0
  21. package/dist/private/node/json-error.d.ts +23 -0
  22. package/dist/private/node/json-error.js +123 -0
  23. package/dist/private/node/json-error.js.map +1 -0
  24. package/dist/private/node/output.js +3 -1
  25. package/dist/private/node/output.js.map +1 -1
  26. package/dist/private/node/output.test.d.ts +1 -0
  27. package/dist/private/node/output.test.js +74 -0
  28. package/dist/private/node/output.test.js.map +1 -0
  29. package/dist/private/node/session/device-authorization.js +49 -15
  30. package/dist/private/node/session/device-authorization.js.map +1 -1
  31. package/dist/private/node/session/validate.js +9 -22
  32. package/dist/private/node/session/validate.js.map +1 -1
  33. package/dist/private/node/ui/alert.d.ts +1 -1
  34. package/dist/private/node/ui/alert.js +29 -3
  35. package/dist/private/node/ui/alert.js.map +1 -1
  36. package/dist/private/node/ui/components/ConcurrentOutput.d.ts +8 -1
  37. package/dist/private/node/ui/components/ConcurrentOutput.js +54 -0
  38. package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -1
  39. package/dist/private/node/ui/components/DangerousConfirmationPrompt.js +3 -3
  40. package/dist/private/node/ui/components/DangerousConfirmationPrompt.js.map +1 -1
  41. package/dist/private/node/ui/components/DangerousConfirmationPrompt.test.js +16 -1
  42. package/dist/private/node/ui/components/DangerousConfirmationPrompt.test.js.map +1 -1
  43. package/dist/private/node/ui/components/Prompts/PromptLayout.js +3 -2
  44. package/dist/private/node/ui/components/Prompts/PromptLayout.js.map +1 -1
  45. package/dist/private/node/ui/components/Prompts/PromptLayout.test.js +20 -1
  46. package/dist/private/node/ui/components/Prompts/PromptLayout.test.js.map +1 -1
  47. package/dist/private/node/ui/components/Tasks.d.ts +2 -9
  48. package/dist/private/node/ui/components/Tasks.js +5 -44
  49. package/dist/private/node/ui/components/Tasks.js.map +1 -1
  50. package/dist/private/node/ui/components/TextPrompt.js +3 -3
  51. package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
  52. package/dist/private/node/ui/components/TextPrompt.test.js +15 -1
  53. package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
  54. package/dist/private/node/ui/components/token-item.d.ts +2 -0
  55. package/dist/private/node/ui/components/token-item.js +26 -0
  56. package/dist/private/node/ui/components/token-item.js.map +1 -1
  57. package/dist/private/node/ui/hooks/use-async-and-unmount.d.ts +3 -3
  58. package/dist/private/node/ui/hooks/use-async-and-unmount.js +2 -2
  59. package/dist/private/node/ui/hooks/use-async-and-unmount.js.map +1 -1
  60. package/dist/private/node/ui/tasks.d.ts +10 -0
  61. package/dist/private/node/ui/tasks.js +68 -0
  62. package/dist/private/node/ui/tasks.js.map +1 -0
  63. package/dist/public/common/command-events.d.ts +125 -0
  64. package/dist/public/common/command-events.js +54 -0
  65. package/dist/public/common/command-events.js.map +1 -0
  66. package/dist/public/common/json-output-schema.d.ts +10 -0
  67. package/dist/public/common/json-output-schema.js +17 -0
  68. package/dist/public/common/json-output-schema.js.map +1 -0
  69. package/dist/public/common/version.d.ts +1 -1
  70. package/dist/public/common/version.js +1 -1
  71. package/dist/public/common/version.js.map +1 -1
  72. package/dist/public/node/api/admin.js +18 -1
  73. package/dist/public/node/api/admin.js.map +1 -1
  74. package/dist/public/node/api/app-management.d.ts +1 -0
  75. package/dist/public/node/api/app-management.js +4 -0
  76. package/dist/public/node/api/app-management.js.map +1 -1
  77. package/dist/public/node/api/bulk-operations/download-bulk-operation-results.d.ts +3 -3
  78. package/dist/public/node/api/bulk-operations/download-bulk-operation-results.js +5 -3
  79. package/dist/public/node/api/bulk-operations/download-bulk-operation-results.js.map +1 -1
  80. package/dist/public/node/base-command.d.ts +6 -0
  81. package/dist/public/node/base-command.js +34 -5
  82. package/dist/public/node/base-command.js.map +1 -1
  83. package/dist/public/node/cli-launcher.js +20 -2
  84. package/dist/public/node/cli-launcher.js.map +1 -1
  85. package/dist/public/node/cli.d.ts +1 -0
  86. package/dist/public/node/cli.js +2 -0
  87. package/dist/public/node/cli.js.map +1 -1
  88. package/dist/public/node/command-events.d.ts +65 -0
  89. package/dist/public/node/command-events.js +71 -0
  90. package/dist/public/node/command-events.js.map +1 -0
  91. package/dist/public/node/context/local.d.ts +6 -0
  92. package/dist/public/node/context/local.js +10 -1
  93. package/dist/public/node/context/local.js.map +1 -1
  94. package/dist/public/node/custom-oclif-loader.d.ts +6 -0
  95. package/dist/public/node/custom-oclif-loader.js +45 -19
  96. package/dist/public/node/custom-oclif-loader.js.map +1 -1
  97. package/dist/public/node/environment.d.ts +2 -1
  98. package/dist/public/node/environment.js +3 -2
  99. package/dist/public/node/environment.js.map +1 -1
  100. package/dist/public/node/error/index.d.ts +91 -0
  101. package/dist/public/node/error/index.js +266 -0
  102. package/dist/public/node/error/index.js.map +1 -0
  103. package/dist/public/node/error/schema.d.ts +472 -0
  104. package/dist/public/node/error/schema.js +54 -0
  105. package/dist/public/node/error/schema.js.map +1 -0
  106. package/dist/public/node/error/types.d.ts +9 -0
  107. package/dist/public/node/error/types.js +2 -0
  108. package/dist/public/node/error/types.js.map +1 -0
  109. package/dist/public/node/error.d.ts +1 -87
  110. package/dist/public/node/error.js +1 -252
  111. package/dist/public/node/error.js.map +1 -1
  112. package/dist/public/node/fs.d.ts +17 -3
  113. package/dist/public/node/fs.js +7 -5
  114. package/dist/public/node/fs.js.map +1 -1
  115. package/dist/public/node/json-output-schema.d.ts +26 -0
  116. package/dist/public/node/json-output-schema.js +30 -0
  117. package/dist/public/node/json-output-schema.js.map +1 -0
  118. package/dist/public/node/local-storage.d.ts +1 -0
  119. package/dist/public/node/local-storage.js +54 -21
  120. package/dist/public/node/local-storage.js.map +1 -1
  121. package/dist/public/node/monorail.d.ts +3 -1
  122. package/dist/public/node/monorail.js +1 -1
  123. package/dist/public/node/monorail.js.map +1 -1
  124. package/dist/public/node/multiple-installation-warning.d.ts +1 -1
  125. package/dist/public/node/multiple-installation-warning.js +2 -3
  126. package/dist/public/node/multiple-installation-warning.js.map +1 -1
  127. package/dist/public/node/no-input.d.ts +11 -0
  128. package/dist/public/node/no-input.js +19 -0
  129. package/dist/public/node/no-input.js.map +1 -0
  130. package/dist/public/node/output.d.ts +6 -0
  131. package/dist/public/node/output.js +40 -0
  132. package/dist/public/node/output.js.map +1 -1
  133. package/dist/public/node/path.js +3 -1
  134. package/dist/public/node/path.js.map +1 -1
  135. package/dist/public/node/system.d.ts +2 -2
  136. package/dist/public/node/system.js +8 -4
  137. package/dist/public/node/system.js.map +1 -1
  138. package/dist/public/node/testing/output.d.ts +30 -0
  139. package/dist/public/node/testing/output.js +83 -0
  140. package/dist/public/node/testing/output.js.map +1 -1
  141. package/dist/public/node/ui.d.ts +5 -1
  142. package/dist/public/node/ui.js +89 -5
  143. package/dist/public/node/ui.js.map +1 -1
  144. package/dist/public/node/upgrade.js +17 -2
  145. package/dist/public/node/upgrade.js.map +1 -1
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +4 -2
@@ -0,0 +1,266 @@
1
+ import { normalizePath } from '../path.js';
2
+ import { flushStdout, stringifyMessage, TokenizedString } from '../output.js';
3
+ import { tokenItemToString } from '../../../private/node/ui/components/token-item.js';
4
+ import { hasRateLimitCode } from '../../../private/node/analytics/graphql-error-codes.js';
5
+ import { isGatewayErrorStatus } from '../../../private/node/api/status-checks.js';
6
+ import { Errors } from '@oclif/core';
7
+ export var FatalErrorType;
8
+ (function (FatalErrorType) {
9
+ // These values are also read from errors created by other cli-kit copies. Do not renumber them.
10
+ FatalErrorType[FatalErrorType["Abort"] = 0] = "Abort";
11
+ FatalErrorType[FatalErrorType["AbortSilent"] = 1] = "AbortSilent";
12
+ FatalErrorType[FatalErrorType["Bug"] = 2] = "Bug";
13
+ })(FatalErrorType || (FatalErrorType = {}));
14
+ export class CancelExecution extends Error {
15
+ }
16
+ /**
17
+ * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.
18
+ * There shouldn't be code that catches fatal errors.
19
+ */
20
+ export class FatalError extends Error {
21
+ tryMessage;
22
+ type;
23
+ nextSteps;
24
+ formattedMessage;
25
+ customSections;
26
+ /** A stable code for JSON consumers to identify this error, included only when known. */
27
+ code;
28
+ /** Selected JSON-serializable data to include in JSON errors. Never attach the raw error or request. */
29
+ details;
30
+ skipOclifErrorHandling;
31
+ /**
32
+ * Creates a new FatalError error.
33
+ *
34
+ * @param message - The error message.
35
+ * @param type - The type of fatal error.
36
+ * @param tryMessage - The message that recommends next steps to the user.
37
+ * You can pass a string a {@link TokenizedString} or a {@link TokenItem}
38
+ * if you need to style the message inside the error Banner component.
39
+ * @param nextSteps - Message to show as "next steps" with suggestions to solve the issue.
40
+ * @param customSections - Custom sections to show in the error banner. To be used if nextSteps is not enough.
41
+ */
42
+ constructor(message, type, tryMessage = null, nextSteps, customSections) {
43
+ const messageIsOutputMessage = typeof message === 'string' || 'value' in message;
44
+ super(messageIsOutputMessage ? stringifyMessage(message) : tokenItemToString(message));
45
+ if (tryMessage) {
46
+ if (tryMessage instanceof TokenizedString) {
47
+ this.tryMessage = stringifyMessage(tryMessage);
48
+ }
49
+ else {
50
+ this.tryMessage = tryMessage;
51
+ }
52
+ }
53
+ else {
54
+ this.tryMessage = null;
55
+ }
56
+ this.type = type;
57
+ this.nextSteps = nextSteps;
58
+ this.customSections = customSections;
59
+ this.skipOclifErrorHandling = true;
60
+ if (!messageIsOutputMessage) {
61
+ this.formattedMessage = message;
62
+ }
63
+ }
64
+ }
65
+ /**
66
+ * An abort error is a fatal error that shouldn't be reported as a bug.
67
+ * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer.
68
+ */
69
+ export class AbortError extends FatalError {
70
+ constructor(message, tryMessage = null, nextSteps, customSections) {
71
+ super(message, FatalErrorType.Abort, tryMessage, nextSteps, customSections);
72
+ }
73
+ }
74
+ /**
75
+ * An external error is similar to Abort but has extra command and args attributes.
76
+ * This is useful to represent errors coming from external commands, usually executed by execa.
77
+ */
78
+ export class ExternalError extends FatalError {
79
+ command;
80
+ args;
81
+ constructor(message, command, args, tryMessage = null) {
82
+ super(message, FatalErrorType.Abort, tryMessage);
83
+ this.command = command;
84
+ this.args = args;
85
+ }
86
+ }
87
+ export class AbortSilentError extends FatalError {
88
+ constructor() {
89
+ super('', FatalErrorType.AbortSilent);
90
+ }
91
+ }
92
+ /**
93
+ * A bug error is an error that represents a bug and therefore should be reported.
94
+ */
95
+ export class BugError extends FatalError {
96
+ constructor(message, tryMessage = null) {
97
+ super(message, FatalErrorType.Bug, tryMessage);
98
+ }
99
+ }
100
+ /**
101
+ * A function that handles errors that blow up in the CLI.
102
+ *
103
+ * @param error - Error to be handled.
104
+ * @returns A promise that resolves with the error passed.
105
+ */
106
+ export async function handler(error) {
107
+ let fatal;
108
+ if (isFatal(error)) {
109
+ fatal = error;
110
+ }
111
+ else if (typeof error === 'string') {
112
+ fatal = new BugError(error);
113
+ }
114
+ else if (error instanceof Error) {
115
+ fatal = new BugError(error.message);
116
+ fatal.stack = error.stack;
117
+ }
118
+ else {
119
+ // errors can come in all shapes and sizes...
120
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
+ const maybeError = error;
122
+ fatal = new BugError(maybeError?.message ?? 'Unknown error');
123
+ if (maybeError?.stack) {
124
+ fatal.stack = maybeError?.stack;
125
+ }
126
+ }
127
+ const { jsonOutputEnabled } = await import('../environment.js');
128
+ if (jsonOutputEnabled()) {
129
+ const { renderFatalErrorAsJson } = await import('../../../private/node/json-error.js');
130
+ renderFatalErrorAsJson(fatal);
131
+ await flushStdout();
132
+ return error;
133
+ }
134
+ const { renderFatalError } = await import('../ui.js');
135
+ renderFatalError(fatal);
136
+ return Promise.resolve(error);
137
+ }
138
+ /**
139
+ * A function that maps an error to an Abort with the stack trace when coming from the CLI.
140
+ *
141
+ * @param error - Error to be mapped.
142
+ * @returns A promise that resolves with the new error object.
143
+ */
144
+ export function errorMapper(error) {
145
+ if (error instanceof Errors.CLIError) {
146
+ const mappedError = new AbortError(error.message);
147
+ mappedError.stack = error.stack;
148
+ return Promise.resolve(mappedError);
149
+ }
150
+ else {
151
+ return Promise.resolve(error);
152
+ }
153
+ }
154
+ /**
155
+ * A function that checks if an error is a fatal one.
156
+ *
157
+ * @param error - Error to be checked.
158
+ * @returns A boolean indicating if the error is a fatal one.
159
+ */
160
+ function isFatal(error) {
161
+ try {
162
+ return Object.prototype.hasOwnProperty.call(error, 'type');
163
+ // eslint-disable-next-line no-catch-all/no-catch-all
164
+ }
165
+ catch {
166
+ return false;
167
+ }
168
+ }
169
+ /**
170
+ * A function that checks if an error should be reported as unexpected.
171
+ *
172
+ * @param error - Error to be checked.
173
+ * @returns A boolean indicating if the error should be reported as unexpected.
174
+ */
175
+ export function shouldReportErrorAsUnexpected(error) {
176
+ if (!isFatal(error)) {
177
+ // this means its not one of the CLI wrapped errors
178
+ if (error instanceof Error) {
179
+ // Raw API errors that slip through unwrapped (e.g. the handleErrors:false path) are expected
180
+ // environmental conditions, not CLI bugs. Treat them as expected so they don't pollute crash
181
+ // reporting.
182
+ if (isExpectedApiError(error)) {
183
+ return false;
184
+ }
185
+ const message = error.message;
186
+ return !errorMessageImpliesEnvironmentIssue(message);
187
+ }
188
+ return true;
189
+ }
190
+ if (error.type === FatalErrorType.Bug) {
191
+ return true;
192
+ }
193
+ return false;
194
+ }
195
+ /**
196
+ * Detects raw graphql-request `ClientError`s that are expected environmental conditions rather than
197
+ * CLI bugs. These reach the reporter as plain `Error`s (not `FatalError`s) and would otherwise be
198
+ * reported as unexpected.
199
+ *
200
+ * HTTP 401 (unauthenticated) is not "transient" in the retry sense — it means the user's session
201
+ * token is expired or invalid, a credential/environment condition (see issue #7891). Rate limiting
202
+ * (HTTP 429, or a `THROTTLED`/`429` GraphQL code on any error in the response) matches the shape
203
+ * detected by `errorsIncludeStatus429` in `private/node/api.ts`. Gateway errors (502/503/504) are
204
+ * also expected infrastructure failures.
205
+ *
206
+ * Scoped to the external `ClientError` shape only — importing the cli-kit `GraphQLClientError`
207
+ * wrapper here would create an `error.ts → headers.ts → error.ts` import cycle.
208
+ *
209
+ * Matched structurally rather than with `instanceof ClientError`, because importing the class
210
+ * pulls `graphql-request` — and through it `graphql`, `tr46` and `whatwg-url` — into the module
211
+ * graph of every command, for one type check on an error path. `ClientError` is the only error
212
+ * reaching here that carries both `response` and `request`; the cli-kit wrapper carries
213
+ * `statusCode` instead (see `private/node/api/headers.ts`).
214
+ *
215
+ * @param error - Error to be checked.
216
+ * @returns A boolean indicating if the error is a known expected API error.
217
+ */
218
+ function isExpectedApiError(error) {
219
+ const candidate = error;
220
+ if (typeof candidate.response !== 'object' || candidate.response === null || candidate.request === undefined) {
221
+ return false;
222
+ }
223
+ const status = candidate.response.status;
224
+ if (status === 401 || status === 429 || isGatewayErrorStatus(status)) {
225
+ return true;
226
+ }
227
+ return hasRateLimitCode(candidate.response.errors);
228
+ }
229
+ /**
230
+ * Stack traces usually have file:// - we strip that and also remove the Windows drive designation.
231
+ *
232
+ * @param filePath - Path to be cleaned.
233
+ * @returns The cleaned path.
234
+ */
235
+ export function cleanSingleStackTracePath(filePath) {
236
+ return normalizePath(filePath)
237
+ .replace('file:/', '/')
238
+ .replace(/^\/?[A-Z]:/, '');
239
+ }
240
+ /**
241
+ * There are certain errors that we know are not due to a CLI bug, but are environmental/user error.
242
+ *
243
+ * @param message - The error message to check.
244
+ * @returns A boolean indicating if the error message implies an environment issue.
245
+ */
246
+ function errorMessageImpliesEnvironmentIssue(message) {
247
+ const environmentIssueMessages = [
248
+ 'EPERM: operation not permitted, scandir',
249
+ 'EPERM: operation not permitted, rename',
250
+ 'EACCES: permission denied',
251
+ 'EPERM: operation not permitted, symlink',
252
+ 'This version of npm supports the following node versions',
253
+ 'EBUSY: resource busy or locked',
254
+ 'ENOTEMPTY: directory not empty',
255
+ 'getaddrinfo ENOTFOUND',
256
+ 'Client network socket disconnected before secure TLS connection was established',
257
+ 'spawn EPERM',
258
+ 'socket hang up',
259
+ 'The user aborted a request.',
260
+ 'write EPIPE',
261
+ 'Unsupported platform',
262
+ ];
263
+ const anyMatches = environmentIssueMessages.some((issueMessage) => message.includes(issueMessage));
264
+ return anyMatches;
265
+ }
266
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/public/node/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,WAAW,EAAiB,gBAAgB,EAAE,eAAe,EAAC,MAAM,cAAc,CAAA;AAC1F,OAAO,EAAC,iBAAiB,EAAmC,MAAM,mDAAmD,CAAA;AACrH,OAAO,EAAC,gBAAgB,EAAC,MAAM,wDAAwD,CAAA;AACvF,OAAO,EAAC,oBAAoB,EAAC,MAAM,4CAA4C,CAAA;AAE/E,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAIlC,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,gGAAgG;IAChG,qDAAS,CA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oB,CAAC,MAAM,CAAC,EAAE,CAAC;QACrE,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,OAAO,aAAa,CAAC,QAAQ,CAAC;SAC3B,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mCAAmC,CAAC,OAAe;IAC1D,MAAM,wBAAwB,GAAG;QAC/B,yCAAyC;QACzC,wCAAwC;QACxC,2BAA2B;QAC3B,yCAAyC;QACzC,0DAA0D;QAC1D,gCAAgC;QAChC,gCAAgC;QAChC,uBAAuB;QACvB,iFAAiF;QACjF,aAAa;QACb,gBAAgB;QAChB,6BAA6B;QAC7B,aAAa;QACb,sBAAsB;KACvB,CAAA;IACD,MAAM,UAAU,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;IAClG,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {normalizePath} from '../path.js'\nimport {flushStdout, OutputMessage, stringifyMessage, TokenizedString} from '../output.js'\nimport {tokenItemToString, type InlineToken, type TokenItem} from '../../../private/node/ui/components/token-item.js'\nimport {hasRateLimitCode} from '../../../private/node/analytics/graphql-error-codes.js'\nimport {isGatewayErrorStatus} from '../../../private/node/api/status-checks.js'\n\nimport {Errors} from '@oclif/core'\n\nimport type {AlertCustomSection} from '../ui.js'\n\nexport enum FatalErrorType {\n // These values are also read from errors created by other cli-kit copies. Do not renumber them.\n Abort = 0,\n AbortSilent = 1,\n Bug = 2,\n}\n\nexport class CancelExecution extends Error {}\n\n/**\n * A fatal error represents an error shouldn't be rescued and that causes the execution to terminate.\n * There shouldn't be code that catches fatal errors.\n */\nexport abstract class FatalError extends Error {\n tryMessage: TokenItem | null\n type: FatalErrorType\n nextSteps?: TokenItem<InlineToken>[]\n formattedMessage?: TokenItem\n customSections?: AlertCustomSection[]\n /** A stable code for JSON consumers to identify this error, included only when known. */\n code?: string\n /** Selected JSON-serializable data to include in JSON errors. Never attach the raw error or request. */\n details?: unknown\n skipOclifErrorHandling: boolean\n /**\n * Creates a new FatalError error.\n *\n * @param message - The error message.\n * @param type - The type of fatal error.\n * @param tryMessage - The message that recommends next steps to the user.\n * You can pass a string a {@link TokenizedString} or a {@link TokenItem}\n * if you need to style the message inside the error Banner component.\n * @param nextSteps - Message to show as \"next steps\" with suggestions to solve the issue.\n * @param customSections - Custom sections to show in the error banner. To be used if nextSteps is not enough.\n */\n constructor(\n message: TokenItem | OutputMessage,\n type: FatalErrorType,\n tryMessage: TokenItem | OutputMessage | null = null,\n nextSteps?: TokenItem<InlineToken>[],\n customSections?: AlertCustomSection[],\n ) {\n const messageIsOutputMessage = typeof message === 'string' || 'value' in message\n super(messageIsOutputMessage ? stringifyMessage(message) : tokenItemToString(message))\n\n if (tryMessage) {\n if (tryMessage instanceof TokenizedString) {\n this.tryMessage = stringifyMessage(tryMessage)\n } else {\n this.tryMessage = tryMessage\n }\n } else {\n this.tryMessage = null\n }\n\n this.type = type\n this.nextSteps = nextSteps\n this.customSections = customSections\n this.skipOclifErrorHandling = true\n\n if (!messageIsOutputMessage) {\n this.formattedMessage = message\n }\n }\n}\n\n/**\n * An abort error is a fatal error that shouldn't be reported as a bug.\n * Those usually represent unexpected scenarios that we can't handle and that usually require some action from the developer.\n */\nexport class AbortError extends FatalError {\n constructor(\n message: TokenItem | OutputMessage,\n tryMessage: TokenItem | OutputMessage | null = null,\n nextSteps?: TokenItem<InlineToken>[],\n customSections?: AlertCustomSection[],\n ) {\n super(message, FatalErrorType.Abort, tryMessage, nextSteps, customSections)\n }\n}\n\n/**\n * An external error is similar to Abort but has extra command and args attributes.\n * This is useful to represent errors coming from external commands, usually executed by execa.\n */\nexport class ExternalError extends FatalError {\n command: string\n args: string[]\n\n constructor(\n message: OutputMessage,\n command: string,\n args: string[],\n tryMessage: TokenItem | OutputMessage | null = null,\n ) {\n super(message, FatalErrorType.Abort, tryMessage)\n this.command = command\n this.args = args\n }\n}\n\nexport class AbortSilentError extends FatalError {\n constructor() {\n super('', FatalErrorType.AbortSilent)\n }\n}\n\n/**\n * A bug error is an error that represents a bug and therefore should be reported.\n */\nexport class BugError extends FatalError {\n constructor(message: TokenItem | OutputMessage, tryMessage: TokenItem | OutputMessage | null = null) {\n super(message, FatalErrorType.Bug, tryMessage)\n }\n}\n\n/**\n * A function that handles errors that blow up in the CLI.\n *\n * @param error - Error to be handled.\n * @returns A promise that resolves with the error passed.\n */\nexport async function handler(error: unknown): Promise<unknown> {\n let fatal: FatalError\n if (isFatal(error)) {\n fatal = error\n } else if (typeof error === 'string') {\n fatal = new BugError(error)\n } else if (error instanceof Error) {\n fatal = new BugError(error.message)\n fatal.stack = error.stack\n } else {\n // errors can come in all shapes and sizes...\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const maybeError = error as any\n fatal = new BugError(maybeError?.message ?? 'Unknown error')\n if (maybeError?.stack) {\n fatal.stack = maybeError?.stack\n }\n }\n\n const {jsonOutputEnabled} = await import('../environment.js')\n if (jsonOutputEnabled()) {\n const {renderFatalErrorAsJson} = await import('../../../private/node/json-error.js')\n renderFatalErrorAsJson(fatal)\n await flushStdout()\n return error\n }\n\n const {renderFatalError} = await import('../ui.js')\n renderFatalError(fatal)\n return Promise.resolve(error)\n}\n\n/**\n * A function that maps an error to an Abort with the stack trace when coming from the CLI.\n *\n * @param error - Error to be mapped.\n * @returns A promise that resolves with the new error object.\n */\nexport function errorMapper(error: unknown): Promise<unknown> {\n if (error instanceof Errors.CLIError) {\n const mappedError = new AbortError(error.message)\n mappedError.stack = error.stack\n return Promise.resolve(mappedError)\n } else {\n return Promise.resolve(error)\n }\n}\n\n/**\n * A function that checks if an error is a fatal one.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error is a fatal one.\n */\nfunction isFatal(error: unknown): error is FatalError {\n try {\n return Object.prototype.hasOwnProperty.call(error, 'type')\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * A function that checks if an error should be reported as unexpected.\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error should be reported as unexpected.\n */\nexport function shouldReportErrorAsUnexpected(error: unknown): boolean {\n if (!isFatal(error)) {\n // this means its not one of the CLI wrapped errors\n if (error instanceof Error) {\n // Raw API errors that slip through unwrapped (e.g. the handleErrors:false path) are expected\n // environmental conditions, not CLI bugs. Treat them as expected so they don't pollute crash\n // reporting.\n if (isExpectedApiError(error)) {\n return false\n }\n const message = error.message\n return !errorMessageImpliesEnvironmentIssue(message)\n }\n return true\n }\n if (error.type === FatalErrorType.Bug) {\n return true\n }\n return false\n}\n\n/**\n * Detects raw graphql-request `ClientError`s that are expected environmental conditions rather than\n * CLI bugs. These reach the reporter as plain `Error`s (not `FatalError`s) and would otherwise be\n * reported as unexpected.\n *\n * HTTP 401 (unauthenticated) is not \"transient\" in the retry sense — it means the user's session\n * token is expired or invalid, a credential/environment condition (see issue #7891). Rate limiting\n * (HTTP 429, or a `THROTTLED`/`429` GraphQL code on any error in the response) matches the shape\n * detected by `errorsIncludeStatus429` in `private/node/api.ts`. Gateway errors (502/503/504) are\n * also expected infrastructure failures.\n *\n * Scoped to the external `ClientError` shape only — importing the cli-kit `GraphQLClientError`\n * wrapper here would create an `error.ts → headers.ts → error.ts` import cycle.\n *\n * Matched structurally rather than with `instanceof ClientError`, because importing the class\n * pulls `graphql-request` — and through it `graphql`, `tr46` and `whatwg-url` — into the module\n * graph of every command, for one type check on an error path. `ClientError` is the only error\n * reaching here that carries both `response` and `request`; the cli-kit wrapper carries\n * `statusCode` instead (see `private/node/api/headers.ts`).\n *\n * @param error - Error to be checked.\n * @returns A boolean indicating if the error is a known expected API error.\n */\nfunction isExpectedApiError(error: Error): boolean {\n const candidate = error as Error & {\n response?: {status?: number; errors?: unknown}\n request?: unknown\n }\n if (typeof candidate.response !== 'object' || candidate.response === null || candidate.request === undefined) {\n return false\n }\n const status = candidate.response.status\n if (status === 401 || status === 429 || isGatewayErrorStatus(status)) {\n return true\n }\n return hasRateLimitCode(candidate.response.errors)\n}\n\n/**\n * Stack traces usually have file:// - we strip that and also remove the Windows drive designation.\n *\n * @param filePath - Path to be cleaned.\n * @returns The cleaned path.\n */\nexport function cleanSingleStackTracePath(filePath: string): string {\n return normalizePath(filePath)\n .replace('file:/', '/')\n .replace(/^\\/?[A-Z]:/, '')\n}\n\n/**\n * There are certain errors that we know are not due to a CLI bug, but are environmental/user error.\n *\n * @param message - The error message to check.\n * @returns A boolean indicating if the error message implies an environment issue.\n */\nfunction errorMessageImpliesEnvironmentIssue(message: string): boolean {\n const environmentIssueMessages = [\n 'EPERM: operation not permitted, scandir',\n 'EPERM: operation not permitted, rename',\n 'EACCES: permission denied',\n 'EPERM: operation not permitted, symlink',\n 'This version of npm supports the following node versions',\n 'EBUSY: resource busy or locked',\n 'ENOTEMPTY: directory not empty',\n 'getaddrinfo ENOTFOUND',\n 'Client network socket disconnected before secure TLS connection was established',\n 'spawn EPERM',\n 'socket hang up',\n 'The user aborted a request.',\n 'write EPIPE',\n 'Unsupported platform',\n ]\n const anyMatches = environmentIssueMessages.some((issueMessage) => message.includes(issueMessage))\n return anyMatches\n}\n"]}