@@ -23,17 +23,16 @@ import (
23
23
"strings"
24
24
25
25
"github.com/arduino/arduino-cli/arduino/sketch"
26
+ "github.com/arduino/arduino-cli/commands"
26
27
"github.com/arduino/arduino-cli/i18n"
27
28
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28
29
paths "github.com/arduino/go-paths-helper"
29
- "google.golang.org/grpc/codes"
30
- "google.golang.org/grpc/status"
31
30
)
32
31
33
32
var tr = i18n .Tr
34
33
35
34
// ArchiveSketch FIXMEDOC
36
- func ArchiveSketch (ctx context.Context , req * rpc.ArchiveSketchRequest ) (* rpc.ArchiveSketchResponse , * status. Status ) {
35
+ func ArchiveSketch (ctx context.Context , req * rpc.ArchiveSketchRequest ) (* rpc.ArchiveSketchResponse , error ) {
37
36
// sketchName is the name of the sketch without extension, for example "MySketch"
38
37
var sketchName string
39
38
@@ -44,7 +43,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
44
43
45
44
s , err := sketch .New (sketchPath )
46
45
if err != nil {
47
- return nil , status . Convert ( err )
46
+ return nil , & commands. SketchNotFoundError { Cause : err }
48
47
}
49
48
50
49
sketchPath = s .FullPath
@@ -57,7 +56,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
57
56
58
57
archivePath , err = archivePath .Clean ().Abs ()
59
58
if err != nil {
60
- return nil , status . Newf ( codes . Unknown , tr ("Error getting absolute archive path %v " ), err )
59
+ return nil , & commands. PermissionDeniedError { Message : tr ("Error getting absolute path of sketch archive " ), Cause : err }
61
60
}
62
61
63
62
// Makes archivePath point to a zip file
@@ -68,18 +67,18 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
68
67
}
69
68
70
69
if archivePath .Exist () {
71
- return nil , status . New ( codes . InvalidArgument , tr ("Archive already exists" ))
70
+ return nil , & commands. InvalidArgumentError { Message : tr ("Archive already exists" )}
72
71
}
73
72
74
73
filesToZip , err := sketchPath .ReadDirRecursive ()
75
74
if err != nil {
76
- return nil , status . Newf ( codes . Unknown , tr ("Error retrieving sketch files: %v " ), err )
75
+ return nil , & commands. PermissionDeniedError { Message : tr ("Error reading sketch files" ), Cause : err }
77
76
}
78
77
filesToZip .FilterOutDirs ()
79
78
80
79
archive , err := archivePath .Create ()
81
80
if err != nil {
82
- return nil , status . Newf ( codes . PermissionDenied , tr ("Error creating archive: %v " ), err )
81
+ return nil , & commands. PermissionDeniedError { Message : tr ("Error creating sketch archive " ), Cause : err }
83
82
}
84
83
defer archive .Close ()
85
84
@@ -91,7 +90,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
91
90
if ! req .IncludeBuildDir {
92
91
filePath , err := sketchPath .Parent ().RelTo (f )
93
92
if err != nil {
94
- return nil , status . Newf ( codes . Unknown , tr ("Error calculating relative file path: %v " ), err )
93
+ return nil , & commands. PermissionDeniedError { Message : tr ("Error calculating relative file path" ), Cause : err }
95
94
}
96
95
97
96
// Skips build folder
@@ -102,9 +101,8 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc
102
101
103
102
// We get the parent path since we want the archive to unpack as a folder.
104
103
// If we don't do this the archive would contain all the sketch files as top level.
105
- err = addFileToSketchArchive (zipWriter , f , sketchPath .Parent ())
106
- if err != nil {
107
- return nil , status .Newf (codes .Unknown , tr ("Error adding file to archive: %v" ), err )
104
+ if err := addFileToSketchArchive (zipWriter , f , sketchPath .Parent ()); err != nil {
105
+ return nil , & commands.PermissionDeniedError {Message : tr ("Error adding file to sketch archive" ), Cause : err }
108
106
}
109
107
}
110
108
0 commit comments