You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Pull apart the error to see if it's a licensing error: if so, we should
424
+
// display a friendlier and more actionable message than the usual GraphQL
425
+
// error output.
426
+
ifgerrs, ok:=err.(api.GraphQlErrors); ok {
427
+
// A licensing error should be the sole error returned, so we'll only
428
+
// pretty print if there's one error.
429
+
iflen(gerrs) ==1 {
430
+
ifcode, cerr:=gerrs[0].Code(); cerr!=nil {
431
+
// We got a malformed value in the error extensions; at this
432
+
// point, there's not much sensible we can do. Let's log this in
433
+
// verbose mode, but let the original error bubble up rather
434
+
// than this one.
435
+
out.Verbosef("Unexpected error parsing the GraphQL error: %v", cerr)
436
+
} elseifcode=="ErrCampaignsUnlicensed" {
437
+
// OK, let's print a better message, then return an
438
+
// exitCodeError to suppress the normal automatic error block.
439
+
// Note that we have hand wrapped the output at 80 (printable)
440
+
// characters: having automatic wrapping some day would be nice,
441
+
// but this should be sufficient for now.
442
+
block:=out.Block(output.Line("🪙", output.StyleWarning, "Campaigns is a paid feature of Sourcegraph. All users can create sample"))
443
+
block.WriteLine(output.Linef("", output.StyleWarning, "campaigns with up to 5 changesets without a license. Contact Sourcegraph sales"))
444
+
block.WriteLine(output.Linef("", output.StyleWarning, "at %shttps://about.sourcegraph.com/contact/sales/%s to obtain a trial license.", output.StyleSearchLink, output.StyleWarning))
445
+
block.Write("")
446
+
block.WriteLine(output.Linef("", output.StyleWarning, "To proceed with this campaign, you will need to create 5 or fewer changesets."))
447
+
block.WriteLine(output.Linef("", output.StyleWarning, "To do so, you could try adding %scount:5%s to your %srepositoriesMatchingQuery%s search,", output.StyleSearchAlertProposedQuery, output.StyleWarning, output.StyleReset, output.StyleWarning))
448
+
block.WriteLine(output.Linef("", output.StyleWarning, "or reduce the number of changesets in %simportChangesets%s.", output.StyleReset, output.StyleWarning))
"message": "The feature \"campaigns\" is not activated because it requires a valid Sourcegraph license. Purchase a Sourcegraph subscription to activate this feature.",
19
+
"path": [
20
+
"createCampaignSpec"
21
+
],
22
+
"extensions": {
23
+
"code": 42
24
+
}
25
+
}
26
+
],
27
+
"data": null
28
+
}`,
29
+
wantErr: true,
30
+
},
31
+
"invalid extensions": {
32
+
in: `{
33
+
"errors": [
34
+
{
35
+
"message": "The feature \"campaigns\" is not activated because it requires a valid Sourcegraph license. Purchase a Sourcegraph subscription to activate this feature.",
36
+
"path": [
37
+
"createCampaignSpec"
38
+
],
39
+
"extensions": 42
40
+
}
41
+
],
42
+
"data": null
43
+
}`,
44
+
wantErr: true,
45
+
},
46
+
"no code": {
47
+
in: `{
48
+
"errors": [
49
+
{
50
+
"message": "The feature \"campaigns\" is not activated because it requires a valid Sourcegraph license. Purchase a Sourcegraph subscription to activate this feature.",
51
+
"path": [
52
+
"createCampaignSpec"
53
+
],
54
+
"extensions": {}
55
+
}
56
+
],
57
+
"data": null
58
+
}`,
59
+
want: "",
60
+
},
61
+
"no extensions": {
62
+
in: `{
63
+
"errors": [
64
+
{
65
+
"message": "The feature \"campaigns\" is not activated because it requires a valid Sourcegraph license. Purchase a Sourcegraph subscription to activate this feature.",
66
+
"path": [
67
+
"createCampaignSpec"
68
+
]
69
+
}
70
+
],
71
+
"data": null
72
+
}`,
73
+
want: "",
74
+
},
75
+
"valid code": {
76
+
in: `{
77
+
"errors": [
78
+
{
79
+
"message": "The feature \"campaigns\" is not activated because it requires a valid Sourcegraph license. Purchase a Sourcegraph subscription to activate this feature.",
0 commit comments