@gadgetinc/ggt 0.3.3 → 0.4.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.
- package/README.md +139 -76
- package/bin/dev.js +4 -7
- package/lib/__generated__/graphql.js.map +1 -1
- package/lib/commands/deploy.js +227 -0
- package/lib/commands/deploy.js.map +1 -0
- package/lib/commands/list.js +20 -16
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/login.js +22 -20
- package/lib/commands/login.js.map +1 -1
- package/lib/commands/logout.js +13 -9
- package/lib/commands/logout.js.map +1 -1
- package/lib/commands/root.js +89 -56
- package/lib/commands/root.js.map +1 -1
- package/lib/commands/sync.js +253 -496
- package/lib/commands/sync.js.map +1 -1
- package/lib/commands/version.js +21 -0
- package/lib/commands/version.js.map +1 -0
- package/lib/commands/whoami.js +15 -11
- package/lib/commands/whoami.js.map +1 -1
- package/lib/main.js +4 -10
- package/lib/main.js.map +1 -1
- package/lib/services/{app.js → app/app.js} +8 -3
- package/lib/services/app/app.js.map +1 -0
- package/lib/services/app/arg.js +28 -0
- package/lib/services/app/arg.js.map +1 -0
- package/lib/services/app/edit-graphql.js +389 -0
- package/lib/services/app/edit-graphql.js.map +1 -0
- package/lib/services/command/arg.js +53 -0
- package/lib/services/command/arg.js.map +1 -0
- package/lib/services/command/command.js +27 -0
- package/lib/services/command/command.js.map +1 -0
- package/lib/services/command/context.js +60 -0
- package/lib/services/command/context.js.map +1 -0
- package/lib/services/{config.js → config/config.js} +29 -31
- package/lib/services/config/config.js.map +1 -0
- package/lib/services/config/env.js +22 -0
- package/lib/services/config/env.js.map +1 -0
- package/lib/services/config/package-json.js +9 -0
- package/lib/services/config/package-json.js.map +1 -0
- package/lib/services/filesync/changes.js +97 -0
- package/lib/services/filesync/changes.js.map +1 -0
- package/lib/services/filesync/conflicts.js +137 -0
- package/lib/services/filesync/conflicts.js.map +1 -0
- package/lib/services/filesync/directory.js +253 -0
- package/lib/services/filesync/directory.js.map +1 -0
- package/lib/services/filesync/error.js +67 -0
- package/lib/services/filesync/error.js.map +1 -0
- package/lib/services/filesync/file.js +3 -0
- package/lib/services/filesync/file.js.map +1 -0
- package/lib/services/filesync/filesync.js +675 -0
- package/lib/services/filesync/filesync.js.map +1 -0
- package/lib/services/filesync/hashes.js +150 -0
- package/lib/services/filesync/hashes.js.map +1 -0
- package/lib/services/http/auth.js +41 -0
- package/lib/services/http/auth.js.map +1 -0
- package/lib/services/http/http.js +64 -0
- package/lib/services/http/http.js.map +1 -0
- package/lib/services/output/log/field.js +3 -0
- package/lib/services/output/log/field.js.map +1 -0
- package/lib/services/output/log/format/format.js +8 -0
- package/lib/services/output/log/format/format.js.map +1 -0
- package/lib/services/output/log/format/json.js +45 -0
- package/lib/services/output/log/format/json.js.map +1 -0
- package/lib/services/output/log/format/pretty.js +147 -0
- package/lib/services/output/log/format/pretty.js.map +1 -0
- package/lib/services/output/log/level.js +41 -0
- package/lib/services/output/log/level.js.map +1 -0
- package/lib/services/output/log/logger.js +40 -0
- package/lib/services/output/log/logger.js.map +1 -0
- package/lib/services/output/log/printer.js +120 -0
- package/lib/services/output/log/printer.js.map +1 -0
- package/lib/services/output/log/structured.js +52 -0
- package/lib/services/output/log/structured.js.map +1 -0
- package/lib/services/{notify.js → output/notify.js} +7 -6
- package/lib/services/output/notify.js.map +1 -0
- package/lib/services/output/prompt.js +52 -0
- package/lib/services/output/prompt.js.map +1 -0
- package/lib/services/output/report.js +162 -0
- package/lib/services/output/report.js.map +1 -0
- package/lib/services/output/sprint.js +21 -0
- package/lib/services/output/sprint.js.map +1 -0
- package/lib/services/output/stream.js +54 -0
- package/lib/services/output/stream.js.map +1 -0
- package/lib/services/{version.js → output/update.js} +24 -16
- package/lib/services/output/update.js.map +1 -0
- package/lib/services/user/session.js +50 -0
- package/lib/services/user/session.js.map +1 -0
- package/lib/services/{user.js → user/user.js} +23 -14
- package/lib/services/user/user.js.map +1 -0
- package/lib/services/util/boolean.js +15 -0
- package/lib/services/util/boolean.js.map +1 -0
- package/lib/services/util/collection.js +38 -0
- package/lib/services/util/collection.js.map +1 -0
- package/lib/services/util/function.js +97 -0
- package/lib/services/util/function.js.map +1 -0
- package/lib/services/{is.js → util/is.js} +7 -0
- package/lib/services/util/is.js.map +1 -0
- package/lib/services/util/number.js +27 -0
- package/lib/services/util/number.js.map +1 -0
- package/lib/services/util/object.js +101 -0
- package/lib/services/util/object.js.map +1 -0
- package/lib/services/util/paths.js +36 -0
- package/lib/services/util/paths.js.map +1 -0
- package/lib/services/{promise.js → util/promise.js} +5 -7
- package/lib/services/util/promise.js.map +1 -0
- package/npm-shrinkwrap.json +2143 -1304
- package/package.json +50 -42
- package/lib/commands/index.js +0 -9
- package/lib/commands/index.js.map +0 -1
- package/lib/services/app.js.map +0 -1
- package/lib/services/args.js +0 -28
- package/lib/services/args.js.map +0 -1
- package/lib/services/collections.js +0 -17
- package/lib/services/collections.js.map +0 -1
- package/lib/services/config.js.map +0 -1
- package/lib/services/debounce.js +0 -21
- package/lib/services/debounce.js.map +0 -1
- package/lib/services/defaults.js +0 -8
- package/lib/services/defaults.js.map +0 -1
- package/lib/services/edit-graphql.js +0 -202
- package/lib/services/edit-graphql.js.map +0 -1
- package/lib/services/errors.js +0 -277
- package/lib/services/errors.js.map +0 -1
- package/lib/services/filesync.js +0 -404
- package/lib/services/filesync.js.map +0 -1
- package/lib/services/fs.js +0 -35
- package/lib/services/fs.js.map +0 -1
- package/lib/services/http.js +0 -53
- package/lib/services/http.js.map +0 -1
- package/lib/services/is.js.map +0 -1
- package/lib/services/log.js +0 -45
- package/lib/services/log.js.map +0 -1
- package/lib/services/noop.js +0 -4
- package/lib/services/noop.js.map +0 -1
- package/lib/services/notify.js.map +0 -1
- package/lib/services/output.js +0 -74
- package/lib/services/output.js.map +0 -1
- package/lib/services/promise.js.map +0 -1
- package/lib/services/prompt.js +0 -22
- package/lib/services/prompt.js.map +0 -1
- package/lib/services/session.js +0 -31
- package/lib/services/session.js.map +0 -1
- package/lib/services/sleep.js +0 -21
- package/lib/services/sleep.js.map +0 -1
- package/lib/services/timeout.js +0 -8
- package/lib/services/timeout.js.map +0 -1
- package/lib/services/user.js.map +0 -1
- package/lib/services/version.js.map +0 -1
package/lib/services/errors.js
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import * as Sentry from "@sentry/node";
|
|
3
|
-
import arg from "arg";
|
|
4
|
-
import cleanStack from "clean-stack";
|
|
5
|
-
import { RequestError } from "got";
|
|
6
|
-
import { randomUUID } from "node:crypto";
|
|
7
|
-
import os from "node:os";
|
|
8
|
-
import { inspect } from "node:util";
|
|
9
|
-
import { serializeError as baseSerializeError } from "serialize-error";
|
|
10
|
-
import { dedent } from "ts-dedent";
|
|
11
|
-
import { compact, uniq } from "./collections.js";
|
|
12
|
-
import { config, env } from "./config.js";
|
|
13
|
-
import { isCloseEvent, isError, isErrorEvent, isGraphQLErrors } from "./is.js";
|
|
14
|
-
import { sprintln2 } from "./output.js";
|
|
15
|
-
let app;
|
|
16
|
-
let user;
|
|
17
|
-
export const setUser = (newUser)=>{
|
|
18
|
-
user = newUser;
|
|
19
|
-
// eslint-disable-next-line unicorn/no-null
|
|
20
|
-
Sentry.setUser(newUser ?? null);
|
|
21
|
-
};
|
|
22
|
-
export const setApp = (newApp)=>{
|
|
23
|
-
app = newApp;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Base class for all errors.
|
|
27
|
-
*/ export class CLIError extends Error {
|
|
28
|
-
/**
|
|
29
|
-
* Constructs a CLIError from a cause.
|
|
30
|
-
*/ static from(cause) {
|
|
31
|
-
if (cause instanceof CLIError) {
|
|
32
|
-
return cause;
|
|
33
|
-
}
|
|
34
|
-
if (cause instanceof arg.ArgError) {
|
|
35
|
-
return new ArgError(cause.message);
|
|
36
|
-
}
|
|
37
|
-
return new UnexpectedError(cause);
|
|
38
|
-
}
|
|
39
|
-
async capture() {
|
|
40
|
-
if (this.isBug === "no") {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
Sentry.getCurrentHub().captureException(this, {
|
|
44
|
-
event_id: this.sentryEventId,
|
|
45
|
-
captureContext: {
|
|
46
|
-
user: user ? {
|
|
47
|
-
id: String(user.id),
|
|
48
|
-
email: user.email,
|
|
49
|
-
username: user.name ?? undefined
|
|
50
|
-
} : undefined,
|
|
51
|
-
tags: {
|
|
52
|
-
applicationId: app ? app.id : undefined,
|
|
53
|
-
arch: config.arch,
|
|
54
|
-
isBug: this.isBug,
|
|
55
|
-
code: this.code,
|
|
56
|
-
environment: env.value,
|
|
57
|
-
platform: config.platform,
|
|
58
|
-
shell: config.shell,
|
|
59
|
-
version: config.version
|
|
60
|
-
},
|
|
61
|
-
contexts: {
|
|
62
|
-
cause: this.cause ? serializeError(this.cause) : undefined,
|
|
63
|
-
app: {
|
|
64
|
-
command: `ggt ${process.argv.slice(2).join(" ")}`,
|
|
65
|
-
argv: process.argv
|
|
66
|
-
},
|
|
67
|
-
device: {
|
|
68
|
-
name: os.hostname(),
|
|
69
|
-
family: os.type(),
|
|
70
|
-
arch: os.arch()
|
|
71
|
-
},
|
|
72
|
-
runtime: {
|
|
73
|
-
name: process.release.name,
|
|
74
|
-
version: process.version
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
await Sentry.flush(2000);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Turns this error into a user-friendly message that explains what went wrong and how to fix it. A good write up of
|
|
83
|
-
* what an error should look like can be found here: {@link https://clig.dev/#errors}
|
|
84
|
-
*/ render() {
|
|
85
|
-
return compact([
|
|
86
|
-
this.header(),
|
|
87
|
-
this.body(),
|
|
88
|
-
this.footer()
|
|
89
|
-
]).join("\n\n");
|
|
90
|
-
}
|
|
91
|
-
header() {
|
|
92
|
-
return `${this.code}: ${this.message}`;
|
|
93
|
-
}
|
|
94
|
-
footer() {
|
|
95
|
-
if (this.isBug === "no") {
|
|
96
|
-
return "";
|
|
97
|
-
}
|
|
98
|
-
return dedent`
|
|
99
|
-
${this.isBug === "yes" ? "This is a bug" : "If you think this is a bug"}, please submit an issue using the link below.
|
|
100
|
-
|
|
101
|
-
https://github.com/gadget-inc/ggt/issues/new?template=bug_report.yml&error-id=${this.sentryEventId}
|
|
102
|
-
`;
|
|
103
|
-
}
|
|
104
|
-
constructor(code, message){
|
|
105
|
-
super(message);
|
|
106
|
-
/**
|
|
107
|
-
* A GGT_CLI_SOMETHING human/machine readable unique identifier for this error.
|
|
108
|
-
*/ _define_property(this, "code", void 0);
|
|
109
|
-
/**
|
|
110
|
-
* The Sentry event ID for this error.
|
|
111
|
-
*/ _define_property(this, "sentryEventId", env.testLike ? "00000000-0000-0000-0000-000000000000" : randomUUID());
|
|
112
|
-
/**
|
|
113
|
-
* The underlying *thing* that caused this error.
|
|
114
|
-
*/ _define_property(this, "cause", void 0);
|
|
115
|
-
/**
|
|
116
|
-
* Assume the stack trace exists.
|
|
117
|
-
*/ _define_property(this, "stack", void 0);
|
|
118
|
-
this.code = code;
|
|
119
|
-
Error.captureStackTrace(this, this.constructor);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Universal Error object to json blob serializer.
|
|
124
|
-
*
|
|
125
|
-
* Wraps `serialize-error` with some handy stuff, like special support
|
|
126
|
-
* for Got HTTP errors
|
|
127
|
-
*/ export const serializeError = (error)=>{
|
|
128
|
-
let serialized = baseSerializeError(Array.isArray(error) ? new AggregateError(error) : error);
|
|
129
|
-
if (typeof serialized == "string") {
|
|
130
|
-
serialized = {
|
|
131
|
-
message: serialized
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
if (error instanceof RequestError) {
|
|
135
|
-
serialized["timings"] = undefined;
|
|
136
|
-
serialized["options"] = {
|
|
137
|
-
method: error.options.method,
|
|
138
|
-
url: error.options.url instanceof URL ? error.options.url.toJSON() : error.options.url
|
|
139
|
-
};
|
|
140
|
-
serialized["responseBody"] = inspect(error.response?.body);
|
|
141
|
-
}
|
|
142
|
-
return serialized;
|
|
143
|
-
};
|
|
144
|
-
export var IsBug;
|
|
145
|
-
(function(IsBug) {
|
|
146
|
-
IsBug["YES"] = "yes";
|
|
147
|
-
IsBug["NO"] = "no";
|
|
148
|
-
IsBug["MAYBE"] = "maybe";
|
|
149
|
-
})(IsBug || (IsBug = {}));
|
|
150
|
-
/**
|
|
151
|
-
* Our "catch all" error. If this error is thrown, we almost certainly have a bug.
|
|
152
|
-
*
|
|
153
|
-
* Whenever possible, we should use a more specific error so that we can provide more useful information.
|
|
154
|
-
*/ export class UnexpectedError extends CLIError {
|
|
155
|
-
body() {
|
|
156
|
-
if (isError(this.cause)) {
|
|
157
|
-
return cleanStack(this.cause.stack ?? this.stack);
|
|
158
|
-
}
|
|
159
|
-
return this.stack;
|
|
160
|
-
}
|
|
161
|
-
constructor(cause){
|
|
162
|
-
super("GGT_CLI_UNEXPECTED_ERROR", "An unexpected error occurred");
|
|
163
|
-
_define_property(this, "cause", void 0);
|
|
164
|
-
_define_property(this, "isBug", void 0);
|
|
165
|
-
this.cause = cause;
|
|
166
|
-
this.isBug = "yes";
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
export class ClientError extends CLIError {
|
|
170
|
-
body() {
|
|
171
|
-
if (isGraphQLErrors(this.cause)) {
|
|
172
|
-
const errors = uniq(this.cause.map((x)=>x.message));
|
|
173
|
-
if (errors.length > 1) {
|
|
174
|
-
let n = 1;
|
|
175
|
-
return sprintln2("Gadget responded with multiple errors:").concat(` ${n++}. ${errors.join(`\n ${n++}. `)}`);
|
|
176
|
-
} else {
|
|
177
|
-
return dedent`
|
|
178
|
-
Gadget responded with the following error:
|
|
179
|
-
|
|
180
|
-
${errors[0]}
|
|
181
|
-
`;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (isCloseEvent(this.cause)) {
|
|
185
|
-
return "The connection to Gadget closed unexpectedly.";
|
|
186
|
-
}
|
|
187
|
-
if (isErrorEvent(this.cause) || isError(this.cause)) {
|
|
188
|
-
return this.cause.message;
|
|
189
|
-
}
|
|
190
|
-
return this.cause;
|
|
191
|
-
}
|
|
192
|
-
constructor(payload, cause){
|
|
193
|
-
super("GGT_CLI_CLIENT_ERROR", "An error occurred while communicating with Gadget");
|
|
194
|
-
_define_property(this, "payload", void 0);
|
|
195
|
-
_define_property(this, "cause", void 0);
|
|
196
|
-
_define_property(this, "isBug", void 0);
|
|
197
|
-
this.payload = payload;
|
|
198
|
-
this.cause = cause;
|
|
199
|
-
this.isBug = "maybe";
|
|
200
|
-
// ErrorEvent and CloseEvent aren't serializable, so we reconstruct
|
|
201
|
-
// them into an object. We discard the `target` property because
|
|
202
|
-
// it's large and not that useful
|
|
203
|
-
if (isErrorEvent(cause)) {
|
|
204
|
-
this.cause = {
|
|
205
|
-
type: cause.type,
|
|
206
|
-
message: cause.message,
|
|
207
|
-
error: serializeError(cause.error)
|
|
208
|
-
};
|
|
209
|
-
} else if (isCloseEvent(cause)) {
|
|
210
|
-
this.cause = {
|
|
211
|
-
type: cause.type,
|
|
212
|
-
code: cause.code,
|
|
213
|
-
reason: cause.reason,
|
|
214
|
-
wasClean: cause.wasClean
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
export class YarnNotFoundError extends CLIError {
|
|
220
|
-
body() {
|
|
221
|
-
return dedent`
|
|
222
|
-
Yarn must be installed to sync your application. You can install it by running:
|
|
223
|
-
|
|
224
|
-
$ npm install --global yarn
|
|
225
|
-
|
|
226
|
-
For more information, see: https://classic.yarnpkg.com/en/docs/install
|
|
227
|
-
`;
|
|
228
|
-
}
|
|
229
|
-
constructor(){
|
|
230
|
-
super("GGT_CLI_YARN_NOT_FOUND", "Yarn not found");
|
|
231
|
-
_define_property(this, "isBug", "no");
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
export class ArgError extends CLIError {
|
|
235
|
-
// eslint-disable-next-line lodash/prefer-constant
|
|
236
|
-
header() {
|
|
237
|
-
return "";
|
|
238
|
-
}
|
|
239
|
-
body() {
|
|
240
|
-
return this.message;
|
|
241
|
-
}
|
|
242
|
-
constructor(message){
|
|
243
|
-
super("GGT_CLI_ARG_ERROR", message);
|
|
244
|
-
_define_property(this, "isBug", "no");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
export class InvalidSyncFileError extends CLIError {
|
|
248
|
-
body() {
|
|
249
|
-
return dedent`
|
|
250
|
-
We failed to read the Gadget metadata file in this directory:
|
|
251
|
-
|
|
252
|
-
${this.dir}
|
|
253
|
-
|
|
254
|
-
If you're running \`ggt sync\` for the first time, we recommend using an empty directory such as:
|
|
255
|
-
|
|
256
|
-
~/gadget/${this.app}
|
|
257
|
-
|
|
258
|
-
Otherwise, if you're sure you want to sync the contents of that directory to Gadget, run \`ggt sync\` again with the \`--force\` flag:
|
|
259
|
-
|
|
260
|
-
$ ggt sync --app ${this.app} ${this.dir} --force
|
|
261
|
-
|
|
262
|
-
You will be prompted to either merge your local files with your remote ones or reset your local files to your remote ones.
|
|
263
|
-
`;
|
|
264
|
-
}
|
|
265
|
-
constructor(dir, app){
|
|
266
|
-
super("GGT_CLI_INVALID_SYNC_FILE", "The .gadget/sync.json file was invalid or not found");
|
|
267
|
-
_define_property(this, "dir", void 0);
|
|
268
|
-
_define_property(this, "app", void 0);
|
|
269
|
-
_define_property(this, "isBug", void 0);
|
|
270
|
-
this.dir = dir;
|
|
271
|
-
this.app = app;
|
|
272
|
-
this.isBug = "maybe";
|
|
273
|
-
this.app ??= "<name of app>";
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/errors.ts"],"sourcesContent":["import * as Sentry from \"@sentry/node\";\nimport arg from \"arg\";\nimport cleanStack from \"clean-stack\";\nimport { RequestError } from \"got\";\nimport type { GraphQLError } from \"graphql\";\nimport { randomUUID } from \"node:crypto\";\nimport os from \"node:os\";\nimport { inspect } from \"node:util\";\nimport { serializeError as baseSerializeError, type ErrorObject } from \"serialize-error\";\nimport { dedent } from \"ts-dedent\";\nimport type { JsonObject } from \"type-fest\";\nimport type { CloseEvent, ErrorEvent } from \"ws\";\nimport type { App } from \"./app.js\";\nimport { compact, uniq } from \"./collections.js\";\nimport { config, env } from \"./config.js\";\nimport type { Payload } from \"./edit-graphql.js\";\nimport { isCloseEvent, isError, isErrorEvent, isGraphQLErrors } from \"./is.js\";\nimport { sprintln2 } from \"./output.js\";\nimport type { User } from \"./user.js\";\n\nlet app: App | undefined;\nlet user: User | undefined;\n\nexport const setUser = (newUser: User | undefined): void => {\n user = newUser;\n // eslint-disable-next-line unicorn/no-null\n Sentry.setUser(newUser ?? null);\n};\n\nexport const setApp = (newApp: App | undefined): void => {\n app = newApp;\n};\n\n/**\n * Base class for all errors.\n */\nexport abstract class CLIError extends Error {\n /**\n * A GGT_CLI_SOMETHING human/machine readable unique identifier for this error.\n */\n code: string;\n\n /**\n * The Sentry event ID for this error.\n */\n sentryEventId = env.testLike ? \"00000000-0000-0000-0000-000000000000\" : randomUUID();\n\n /**\n * The underlying *thing* that caused this error.\n */\n cause?: unknown;\n\n /**\n * Assume the stack trace exists.\n */\n override stack!: string;\n\n /**\n * Indicates whether this error is considered a bug or not.\n */\n abstract isBug: IsBug;\n\n constructor(code: string, message: string) {\n super(message);\n this.code = code;\n Error.captureStackTrace(this, this.constructor);\n }\n\n /**\n * Constructs a CLIError from a cause.\n */\n static from(cause: unknown): CLIError {\n if (cause instanceof CLIError) {\n return cause;\n }\n if (cause instanceof arg.ArgError) {\n return new ArgError(cause.message);\n }\n return new UnexpectedError(cause);\n }\n\n async capture(): Promise<void> {\n if (this.isBug === IsBug.NO) {\n return;\n }\n\n Sentry.getCurrentHub().captureException(this, {\n event_id: this.sentryEventId,\n captureContext: {\n user: user ? { id: String(user.id), email: user.email, username: user.name ?? undefined } : undefined,\n tags: {\n applicationId: app ? app.id : undefined,\n arch: config.arch,\n isBug: this.isBug,\n code: this.code,\n environment: env.value,\n platform: config.platform,\n shell: config.shell,\n version: config.version,\n },\n contexts: {\n cause: this.cause ? serializeError(this.cause) : undefined,\n app: {\n command: `ggt ${process.argv.slice(2).join(\" \")}`,\n argv: process.argv,\n },\n device: {\n name: os.hostname(),\n family: os.type(),\n arch: os.arch(),\n },\n runtime: {\n name: process.release.name,\n version: process.version,\n },\n },\n },\n });\n\n await Sentry.flush(2000);\n }\n\n /**\n * Turns this error into a user-friendly message that explains what went wrong and how to fix it. A good write up of\n * what an error should look like can be found here: {@link https://clig.dev/#errors}\n */\n render(): string {\n return compact([this.header(), this.body(), this.footer()]).join(\"\\n\\n\");\n }\n\n protected header(): string {\n return `${this.code}: ${this.message}`;\n }\n\n protected footer(): string {\n if (this.isBug === IsBug.NO) {\n return \"\";\n }\n\n return dedent`\n ${this.isBug === IsBug.YES ? \"This is a bug\" : \"If you think this is a bug\"}, please submit an issue using the link below.\n\n https://github.com/gadget-inc/ggt/issues/new?template=bug_report.yml&error-id=${this.sentryEventId}\n `;\n }\n\n protected abstract body(): string;\n}\n\n/**\n * Universal Error object to json blob serializer.\n *\n * Wraps `serialize-error` with some handy stuff, like special support\n * for Got HTTP errors\n */\nexport const serializeError = (error: unknown): ErrorObject => {\n let serialized = baseSerializeError(Array.isArray(error) ? new AggregateError(error) : error);\n if (typeof serialized == \"string\") {\n serialized = { message: serialized };\n }\n\n if (error instanceof RequestError) {\n serialized[\"timings\"] = undefined;\n serialized[\"options\"] = {\n method: error.options.method,\n url: error.options.url instanceof URL ? error.options.url.toJSON() : error.options.url,\n };\n serialized[\"responseBody\"] = inspect(error.response?.body);\n }\n\n return serialized;\n};\n\nexport enum IsBug {\n YES = \"yes\",\n NO = \"no\",\n MAYBE = \"maybe\",\n}\n\n/**\n * Our \"catch all\" error. If this error is thrown, we almost certainly have a bug.\n *\n * Whenever possible, we should use a more specific error so that we can provide more useful information.\n */\nexport class UnexpectedError extends CLIError {\n isBug = IsBug.YES;\n\n constructor(override cause: unknown) {\n super(\"GGT_CLI_UNEXPECTED_ERROR\", \"An unexpected error occurred\");\n }\n\n protected body(): string {\n if (isError(this.cause)) {\n return cleanStack(this.cause.stack ?? this.stack);\n }\n return this.stack;\n }\n}\n\nexport class ClientError extends CLIError {\n isBug = IsBug.MAYBE;\n\n constructor(\n readonly payload: Payload<JsonObject, JsonObject>,\n override cause: string | Error | readonly GraphQLError[] | CloseEvent | ErrorEvent,\n ) {\n super(\"GGT_CLI_CLIENT_ERROR\", \"An error occurred while communicating with Gadget\");\n\n // ErrorEvent and CloseEvent aren't serializable, so we reconstruct\n // them into an object. We discard the `target` property because\n // it's large and not that useful\n if (isErrorEvent(cause)) {\n this.cause = {\n type: cause.type,\n message: cause.message,\n error: serializeError(cause.error),\n } as ErrorEvent;\n } else if (isCloseEvent(cause)) {\n this.cause = {\n type: cause.type,\n code: cause.code,\n reason: cause.reason,\n wasClean: cause.wasClean,\n } as CloseEvent;\n }\n }\n\n override body(): string {\n if (isGraphQLErrors(this.cause)) {\n const errors = uniq(this.cause.map((x) => x.message));\n if (errors.length > 1) {\n let n = 1;\n return sprintln2(\"Gadget responded with multiple errors:\").concat(` ${n++}. ${errors.join(`\\n ${n++}. `)}`);\n } else {\n return dedent`\n Gadget responded with the following error:\n\n ${errors[0]}\n `;\n }\n }\n\n if (isCloseEvent(this.cause)) {\n return \"The connection to Gadget closed unexpectedly.\";\n }\n\n if (isErrorEvent(this.cause) || isError(this.cause)) {\n return this.cause.message;\n }\n\n return this.cause;\n }\n}\n\nexport class YarnNotFoundError extends CLIError {\n isBug = IsBug.NO;\n\n constructor() {\n super(\"GGT_CLI_YARN_NOT_FOUND\", \"Yarn not found\");\n }\n\n protected body(): string {\n return dedent`\n Yarn must be installed to sync your application. You can install it by running:\n\n $ npm install --global yarn\n\n For more information, see: https://classic.yarnpkg.com/en/docs/install\n `;\n }\n}\n\nexport class ArgError extends CLIError {\n isBug = IsBug.NO;\n\n constructor(message: string) {\n super(\"GGT_CLI_ARG_ERROR\", message);\n }\n\n // eslint-disable-next-line lodash/prefer-constant\n protected override header(): string {\n return \"\";\n }\n\n protected override body(): string {\n return this.message;\n }\n}\n\nexport class InvalidSyncFileError extends CLIError {\n isBug = IsBug.MAYBE;\n\n constructor(\n readonly dir: string,\n readonly app: string | undefined,\n ) {\n super(\"GGT_CLI_INVALID_SYNC_FILE\", \"The .gadget/sync.json file was invalid or not found\");\n this.app ??= \"<name of app>\";\n }\n\n protected body(): string {\n return dedent`\n We failed to read the Gadget metadata file in this directory:\n\n ${this.dir}\n\n If you're running \\`ggt sync\\` for the first time, we recommend using an empty directory such as:\n\n ~/gadget/${this.app}\n\n Otherwise, if you're sure you want to sync the contents of that directory to Gadget, run \\`ggt sync\\` again with the \\`--force\\` flag:\n\n $ ggt sync --app ${this.app} ${this.dir} --force\n\n You will be prompted to either merge your local files with your remote ones or reset your local files to your remote ones.\n `;\n }\n}\n"],"names":["Sentry","arg","cleanStack","RequestError","randomUUID","os","inspect","serializeError","baseSerializeError","dedent","compact","uniq","config","env","isCloseEvent","isError","isErrorEvent","isGraphQLErrors","sprintln2","app","user","setUser","newUser","setApp","newApp","CLIError","Error","from","cause","ArgError","message","UnexpectedError","capture","isBug","getCurrentHub","captureException","event_id","sentryEventId","captureContext","id","String","email","username","name","undefined","tags","applicationId","arch","code","environment","value","platform","shell","version","contexts","command","process","argv","slice","join","device","hostname","family","type","runtime","release","flush","render","header","body","footer","constructor","testLike","stack","captureStackTrace","error","serialized","Array","isArray","AggregateError","method","options","url","URL","toJSON","response","IsBug","ClientError","errors","map","x","length","n","concat","payload","reason","wasClean","YarnNotFoundError","InvalidSyncFileError","dir"],"mappings":";AAAA,YAAYA,YAAY,eAAe;AACvC,OAAOC,SAAS,MAAM;AACtB,OAAOC,gBAAgB,cAAc;AACrC,SAASC,YAAY,QAAQ,MAAM;AAEnC,SAASC,UAAU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