forked from arduino/arduino-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors.go
870 lines (691 loc) · 23.6 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].
package arduino
import (
"fmt"
"strings"
"github.com/arduino/arduino-cli/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var tr = i18n.Tr
func composeErrorMsg(msg string, cause error) string {
if cause == nil {
return msg
}
return fmt.Sprintf("%v: %v", msg, cause)
}
// CommandError is an error that may be converted into a gRPC status.
type CommandError interface {
// ToRPCStatus convertes the error into a *status.Status
ToRPCStatus() *status.Status
}
// InvalidInstanceError is returned if the instance used in the command is not valid.
type InvalidInstanceError struct{}
func (e *InvalidInstanceError) Error() string {
return tr("Invalid instance")
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidInstanceError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// InvalidFQBNError is returned when the FQBN has syntax errors
type InvalidFQBNError struct {
Cause error
}
func (e *InvalidFQBNError) Error() string {
return composeErrorMsg(tr("Invalid FQBN"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidFQBNError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
func (e *InvalidFQBNError) Unwrap() error {
return e.Cause
}
// InvalidURLError is returned when the URL has syntax errors
type InvalidURLError struct {
Cause error
}
func (e *InvalidURLError) Error() string {
return composeErrorMsg(tr("Invalid URL"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidURLError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
func (e *InvalidURLError) Unwrap() error {
return e.Cause
}
// InvalidLibraryError is returned when the library has syntax errors
type InvalidLibraryError struct {
Cause error
}
func (e *InvalidLibraryError) Error() string {
return composeErrorMsg(tr("Invalid library"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidLibraryError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
func (e *InvalidLibraryError) Unwrap() error {
return e.Cause
}
// InvalidVersionError is returned when the version has syntax errors
type InvalidVersionError struct {
Cause error
}
func (e *InvalidVersionError) Error() string {
return composeErrorMsg(tr("Invalid version"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidVersionError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
func (e *InvalidVersionError) Unwrap() error {
return e.Cause
}
// NoBoardsDetectedError is returned when detecting the FQBN of a board
// does not produce any result.
type NoBoardsDetectedError struct {
Port *rpc.Port
}
func (e *NoBoardsDetectedError) Error() string {
return tr(
"Please specify an FQBN. The board on port %[1]s with protocol %[2]s can't be identified",
e.Port.Address,
e.Port.Protocol,
)
}
// ToRPCStatus converts the error into a *status.Status
func (e *NoBoardsDetectedError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MultipleBoardsDetectedError is returned when trying to detect
// the FQBN of a board connected to a port fails because that
// are multiple possible boards detected.
type MultipleBoardsDetectedError struct {
Port *rpc.Port
}
func (e *MultipleBoardsDetectedError) Error() string {
return tr(
"Please specify an FQBN. Multiple possible boards detected on port %[1]s with protocol %[2]s",
e.Port.Address,
e.Port.Protocol,
)
}
// ToRPCStatus converts the error into a *status.Status
func (e *MultipleBoardsDetectedError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MissingFQBNError is returned when the FQBN is mandatory and not specified
type MissingFQBNError struct{}
func (e *MissingFQBNError) Error() string {
return tr("Missing FQBN (Fully Qualified Board Name)")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingFQBNError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// UnknownFQBNError is returned when the FQBN is not found
type UnknownFQBNError struct {
Cause error
}
func (e *UnknownFQBNError) Error() string {
return composeErrorMsg(tr("Unknown FQBN"), e.Cause)
}
func (e *UnknownFQBNError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *UnknownFQBNError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// UnknownProfileError is returned when the profile is not found
type UnknownProfileError struct {
Profile string
Cause error
}
func (e *UnknownProfileError) Error() string {
return composeErrorMsg(tr("Profile '%s' not found", e.Profile), e.Cause)
}
func (e *UnknownProfileError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *UnknownProfileError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// InvalidProfileError is returned when the profile has errors
type InvalidProfileError struct {
Cause error
}
func (e *InvalidProfileError) Error() string {
return composeErrorMsg(tr("Invalid profile"), e.Cause)
}
func (e *InvalidProfileError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidProfileError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
// MissingPortAddressError is returned when the port protocol is mandatory and not specified
type MissingPortAddressError struct{}
func (e *MissingPortAddressError) Error() string {
return tr("Missing port address")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingPortAddressError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MissingPortProtocolError is returned when the port protocol is mandatory and not specified
type MissingPortProtocolError struct{}
func (e *MissingPortProtocolError) Error() string {
return tr("Missing port protocol")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingPortProtocolError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MissingPortError is returned when the port is mandatory and not specified
type MissingPortError struct{}
func (e *MissingPortError) Error() string {
return tr("Missing port")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingPortError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// NoMonitorAvailableForProtocolError is returned when a monitor for the specified port protocol is not available
type NoMonitorAvailableForProtocolError struct {
Protocol string
}
func (e *NoMonitorAvailableForProtocolError) Error() string {
return tr("No monitor available for the port protocol %s", e.Protocol)
}
// ToRPCStatus converts the error into a *status.Status
func (e *NoMonitorAvailableForProtocolError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MissingProgrammerError is returned when the programmer is mandatory and not specified
type MissingProgrammerError struct{}
func (e *MissingProgrammerError) Error() string {
return tr("Missing programmer")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingProgrammerError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// ProgrammerRequiredForUploadError is returned when the upload can be done only using a programmer
type ProgrammerRequiredForUploadError struct{}
func (e *ProgrammerRequiredForUploadError) Error() string {
return tr("A programmer is required to upload")
}
// ToRPCStatus converts the error into a *status.Status
func (e *ProgrammerRequiredForUploadError) ToRPCStatus() *status.Status {
st, _ := status.
New(codes.InvalidArgument, e.Error()).
WithDetails(&rpc.ProgrammerIsRequiredForUploadError{})
return st
}
// InitFailedError is returned when the instance initialization fails
type InitFailedError struct {
Code codes.Code
Cause error
Reason rpc.FailedInstanceInitReason
}
func (ife *InitFailedError) Error() string {
return ife.Cause.Error()
}
// ToRPCStatus converts the error into a *status.Status
func (ife *InitFailedError) ToRPCStatus() *status.Status {
st, _ := status.
New(ife.Code, ife.Cause.Error()).
WithDetails(&rpc.FailedInstanceInitError{
Reason: ife.Reason,
Message: ife.Cause.Error(),
})
return st
}
// ProgrammerNotFoundError is returned when the programmer is not found
type ProgrammerNotFoundError struct {
Programmer string
Cause error
}
func (e *ProgrammerNotFoundError) Error() string {
return composeErrorMsg(tr("Programmer '%s' not found", e.Programmer), e.Cause)
}
func (e *ProgrammerNotFoundError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *ProgrammerNotFoundError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// MonitorNotFoundError is returned when the pluggable monitor is not found
type MonitorNotFoundError struct {
Monitor string
Cause error
}
func (e *MonitorNotFoundError) Error() string {
return composeErrorMsg(tr("Monitor '%s' not found", e.Monitor), e.Cause)
}
func (e *MonitorNotFoundError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *MonitorNotFoundError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// InvalidPlatformPropertyError is returned when a property in the platform is not valid
type InvalidPlatformPropertyError struct {
Property string
Value string
}
func (e *InvalidPlatformPropertyError) Error() string {
return tr("Invalid '%[1]s' property: %[2]s", e.Property, e.Value)
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidPlatformPropertyError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
// MissingPlatformPropertyError is returned when a property in the platform is not found
type MissingPlatformPropertyError struct {
Property string
}
func (e *MissingPlatformPropertyError) Error() string {
return tr("Property '%s' is undefined", e.Property)
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingPlatformPropertyError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
// PlatformNotFoundError is returned when a platform is not found
type PlatformNotFoundError struct {
Platform string
Cause error
}
func (e *PlatformNotFoundError) Error() string {
return composeErrorMsg(tr("Platform '%s' not found", e.Platform), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *PlatformNotFoundError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
func (e *PlatformNotFoundError) Unwrap() error {
return e.Cause
}
// PlatformLoadingError is returned when a platform has fatal errors that prevents loading
type PlatformLoadingError struct {
Cause error
}
func (e *PlatformLoadingError) Error() string {
return composeErrorMsg(tr("Error loading hardware platform"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *PlatformLoadingError) ToRPCStatus() *status.Status {
s, _ := status.New(codes.FailedPrecondition, e.Error()).
WithDetails(&rpc.PlatformLoadingError{})
return s
}
func (e *PlatformLoadingError) Unwrap() error {
return e.Cause
}
// LibraryNotFoundError is returned when a platform is not found
type LibraryNotFoundError struct {
Library string
Cause error
}
func (e *LibraryNotFoundError) Error() string {
return composeErrorMsg(tr("Library '%s' not found", e.Library), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *LibraryNotFoundError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
func (e *LibraryNotFoundError) Unwrap() error {
return e.Cause
}
// LibraryDependenciesResolutionFailedError is returned when an inconsistency is found in library dependencies
// or a solution cannot be found.
type LibraryDependenciesResolutionFailedError struct {
Cause error
}
func (e *LibraryDependenciesResolutionFailedError) Error() string {
return composeErrorMsg(tr("No valid dependencies solution found"), e.Cause)
}
// ToRPCStatus converts the error into a *status.Status
func (e *LibraryDependenciesResolutionFailedError) ToRPCStatus() *status.Status {
return status.New(codes.FailedPrecondition, e.Error())
}
func (e *LibraryDependenciesResolutionFailedError) Unwrap() error {
return e.Cause
}
// PlatformAlreadyAtTheLatestVersionError is returned when a platform is up to date
type PlatformAlreadyAtTheLatestVersionError struct {
Platform string
}
func (e *PlatformAlreadyAtTheLatestVersionError) Error() string {
return tr("Platform '%s' is already at the latest version", e.Platform)
}
// ToRPCStatus converts the error into a *status.Status
func (e *PlatformAlreadyAtTheLatestVersionError) ToRPCStatus() *status.Status {
st, _ := status.
New(codes.AlreadyExists, e.Error()).
WithDetails(&rpc.AlreadyAtLatestVersionError{})
return st
}
// MissingSketchPathError is returned when the sketch path is mandatory and not specified
type MissingSketchPathError struct{}
func (e *MissingSketchPathError) Error() string {
return tr("Missing sketch path")
}
// ToRPCStatus converts the error into a *status.Status
func (e *MissingSketchPathError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// CantCreateSketchError is returned when the sketch cannot be created
type CantCreateSketchError struct {
Cause error
}
func (e *CantCreateSketchError) Error() string {
return composeErrorMsg(tr("Can't create sketch"), e.Cause)
}
func (e *CantCreateSketchError) Unwrap() error {
return e.Cause
}
// CantUpdateSketchError is returned when the sketch cannot be updated
type CantUpdateSketchError struct {
Cause error
}
func (e *CantUpdateSketchError) Error() string {
return composeErrorMsg(tr("Can't update sketch"), e.Cause)
}
func (e *CantUpdateSketchError) Unwrap() error {
return e.Cause
}
// CantOpenSketchError is returned when the sketch is not found or cannot be opened
type CantOpenSketchError struct {
Cause error
}
func (e *CantOpenSketchError) Error() string {
return composeErrorMsg(tr("Can't open sketch"), e.Cause)
}
func (e *CantOpenSketchError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *CantOpenSketchError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// FailedInstallError is returned if an install operation fails
type FailedInstallError struct {
Message string
Cause error
}
func (e *FailedInstallError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *FailedInstallError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedInstallError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedLibraryInstallError is returned if a library install operation fails
type FailedLibraryInstallError struct {
Cause error
}
func (e *FailedLibraryInstallError) Error() string {
return composeErrorMsg(tr("Library install failed"), e.Cause)
}
func (e *FailedLibraryInstallError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedLibraryInstallError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedUninstallError is returned if an uninstall operation fails
type FailedUninstallError struct {
Message string
Cause error
}
func (e *FailedUninstallError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *FailedUninstallError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedUninstallError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedDownloadError is returned when a network download fails
type FailedDownloadError struct {
Message string
Cause error
}
func (e *FailedDownloadError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *FailedDownloadError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedDownloadError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedUploadError is returned when the upload fails
type FailedUploadError struct {
Message string
Cause error
}
func (e *FailedUploadError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *FailedUploadError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedUploadError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedDebugError is returned when the debug fails
type FailedDebugError struct {
Message string
Cause error
}
func (e *FailedDebugError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *FailedDebugError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedDebugError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// FailedMonitorError is returned when opening the monitor port of a board fails
type FailedMonitorError struct {
Cause error
}
func (e *FailedMonitorError) Error() string {
return composeErrorMsg(tr("Port monitor error"), e.Cause)
}
func (e *FailedMonitorError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *FailedMonitorError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// CompileFailedError is returned when the compile fails
type CompileFailedError struct {
Message string
Cause error
}
func (e *CompileFailedError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *CompileFailedError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *CompileFailedError) ToRPCStatus() *status.Status {
return status.New(codes.Internal, e.Error())
}
// InvalidArgumentError is returned when an invalid argument is passed to the command
type InvalidArgumentError struct {
Message string
Cause error
}
func (e *InvalidArgumentError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *InvalidArgumentError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *InvalidArgumentError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// NotFoundError is returned when a resource is not found
type NotFoundError struct {
Message string
Cause error
}
func (e *NotFoundError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *NotFoundError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *NotFoundError) ToRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
// PermissionDeniedError is returned when a resource cannot be accessed or modified
type PermissionDeniedError struct {
Message string
Cause error
}
func (e *PermissionDeniedError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *PermissionDeniedError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *PermissionDeniedError) ToRPCStatus() *status.Status {
return status.New(codes.PermissionDenied, e.Error())
}
// UnavailableError is returned when a resource is temporarily not available
type UnavailableError struct {
Message string
Cause error
}
func (e *UnavailableError) Error() string {
return composeErrorMsg(e.Message, e.Cause)
}
func (e *UnavailableError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *UnavailableError) ToRPCStatus() *status.Status {
return status.New(codes.Unavailable, e.Error())
}
// TempDirCreationFailedError is returned if a temp dir could not be created
type TempDirCreationFailedError struct {
Cause error
}
func (e *TempDirCreationFailedError) Error() string {
return composeErrorMsg(tr("Cannot create temp dir"), e.Cause)
}
func (e *TempDirCreationFailedError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *TempDirCreationFailedError) ToRPCStatus() *status.Status {
return status.New(codes.Unavailable, e.Error())
}
// TempFileCreationFailedError is returned if a temp file could not be created
type TempFileCreationFailedError struct {
Cause error
}
func (e *TempFileCreationFailedError) Error() string {
return composeErrorMsg(tr("Cannot create temp file"), e.Cause)
}
func (e *TempFileCreationFailedError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *TempFileCreationFailedError) ToRPCStatus() *status.Status {
return status.New(codes.Unavailable, e.Error())
}
// SignatureVerificationFailedError is returned if a signature verification fails
type SignatureVerificationFailedError struct {
File string
Cause error
}
func (e *SignatureVerificationFailedError) Error() string {
return composeErrorMsg(tr("'%s' has an invalid signature", e.File), e.Cause)
}
func (e *SignatureVerificationFailedError) Unwrap() error {
return e.Cause
}
// ToRPCStatus converts the error into a *status.Status
func (e *SignatureVerificationFailedError) ToRPCStatus() *status.Status {
return status.New(codes.Unavailable, e.Error())
}
// MultiplePlatformsError is returned when trying to detect
// the Platform the user is trying to interact with and
// and multiple results are found.
type MultiplePlatformsError struct {
Platforms []string
UserPlatform string
}
func (e *MultiplePlatformsError) Error() string {
return tr("Found %d platforms matching \"%s\": %s",
len(e.Platforms), e.UserPlatform, strings.Join(e.Platforms, ", "))
}
// ToRPCStatus converts the error into a *status.Status
func (e *MultiplePlatformsError) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}
// MultipleLibraryInstallDetected is returned when the user request an
// operation on a library but multiple libraries with the same name
// (in library.properties) are detected.
type MultipleLibraryInstallDetected struct {
LibName string
LibsDir paths.PathList
Message string
}
func (e *MultipleLibraryInstallDetected) Error() string {
res := tr("The library %s has multiple installations:", e.LibName) + "\n"
for _, lib := range e.LibsDir {
res += fmt.Sprintf("- %s\n", lib)
}
res += e.Message
return res
}
// ToRPCStatus converts the error into a *status.Status
func (e *MultipleLibraryInstallDetected) ToRPCStatus() *status.Status {
return status.New(codes.InvalidArgument, e.Error())
}