7
7
"sort"
8
8
"strings"
9
9
10
- "google.golang.org/grpc/codes"
11
- "google.golang.org/grpc/status"
12
-
13
10
builder "github.com/arduino/arduino-builder"
14
11
"github.com/arduino/arduino-builder/types"
15
12
"github.com/arduino/arduino-cli/arduino/cores"
@@ -31,19 +28,19 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
31
28
}
32
29
sketch , err := cli .InitSketch (sketchPath )
33
30
if err != nil {
34
- return nil , status .Errorf (codes . Internal , "Error opening sketch: %s" , err )
31
+ return nil , fmt .Errorf (" opening sketch: %s" , err )
35
32
}
36
33
37
34
fqbnIn := req .GetFqbn ()
38
35
if fqbnIn == "" && sketch != nil && sketch .Metadata != nil {
39
36
fqbnIn = sketch .Metadata .CPU .Fqbn
40
37
}
41
38
if fqbnIn == "" {
42
- return nil , status . Error ( codes . InvalidArgument , "No Fully Qualified Board Name provided" )
39
+ return nil , fmt . Errorf ( "No Fully Qualified Board Name provided" )
43
40
}
44
41
fqbn , err := cores .ParseFQBN (fqbnIn )
45
42
if err != nil {
46
- return nil , status . Error ( codes . InvalidArgument , "Fully Qualified Board Name has incorrect format" )
43
+ return nil , fmt . Errorf ( " incorrect FQBN: %s" , err )
47
44
}
48
45
49
46
pm , _ := cli .InitPackageAndLibraryManager ()
@@ -57,12 +54,12 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
57
54
core .InstallToolRelease (pm , ctags )
58
55
59
56
if err := pm .LoadHardware (cli .Config ); err != nil {
60
- return nil , status .Errorf (codes . Internal , "Could not load hardware packages: %s" , err )
57
+ return nil , fmt .Errorf ("loading hardware packages: %s" , err )
61
58
}
62
59
ctags , _ = getBuiltinCtagsTool (pm )
63
60
if ! ctags .IsInstalled () {
64
61
formatter .PrintErrorMessage ("Missing ctags tool." )
65
- return nil , status . Error ( codes . Internal , "Missing ctags tool" )
62
+ return nil , fmt . Errorf ( "Missing ctags tool" )
66
63
}
67
64
}
68
65
@@ -75,7 +72,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
75
72
"\" %[1]s:%[2]s\" platform is not installed, please install it by running \" " +
76
73
cli .AppName + " core install %[1]s:%[2]s\" ." , fqbn .Package , fqbn .PlatformArch )
77
74
formatter .PrintErrorMessage (errorMessage )
78
- return nil , status .Errorf (codes . Internal , "Platform not installed. " )
75
+ return nil , fmt .Errorf ("Platform not installed" )
79
76
}
80
77
81
78
builderCtx := & types.Context {}
@@ -87,13 +84,13 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
87
84
if packagesDir , err := cli .Config .HardwareDirectories (); err == nil {
88
85
builderCtx .HardwareDirs = packagesDir
89
86
} else {
90
- return nil , status .Errorf (codes . Internal , "Cannot get hardware directories: %s" , err )
87
+ return nil , fmt .Errorf ("cannot get hardware directories: %s" , err )
91
88
}
92
89
93
90
if toolsDir , err := cli .Config .BundleToolsDirectories (); err == nil {
94
91
builderCtx .ToolsDirs = toolsDir
95
92
} else {
96
- return nil , status .Errorf (codes . Internal , "Cannot get bundled tools directories: %s" , err )
93
+ return nil , fmt .Errorf ("cannot get bundled tools directories: %s" , err )
97
94
}
98
95
99
96
builderCtx .OtherLibrariesDirs = paths .NewPathList ()
@@ -103,7 +100,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
103
100
builderCtx .BuildPath = paths .New (req .GetBuildPath ())
104
101
err = builderCtx .BuildPath .MkdirAll ()
105
102
if err != nil {
106
- return nil , status .Errorf (codes . Internal , "Cannot create the build directory: %s" , err )
103
+ return nil , fmt .Errorf ("cannot create build directory: %s" , err )
107
104
}
108
105
}
109
106
@@ -126,7 +123,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
126
123
builderCtx .BuildCachePath = paths .New (req .GetBuildCachePath ())
127
124
err = builderCtx .BuildCachePath .MkdirAll ()
128
125
if err != nil {
129
- return nil , status .Errorf (codes . Internal , "Cannot create the build cache directory: %s" , err )
126
+ return nil , fmt .Errorf ("cannot create build cache directory: %s" , err )
130
127
}
131
128
}
132
129
@@ -160,7 +157,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
160
157
}
161
158
162
159
if err != nil {
163
- return nil , status .Errorf (codes . Internal , "Build failed: %s" , err )
160
+ return nil , fmt .Errorf ("build failed: %s" , err )
164
161
}
165
162
166
163
// FIXME: Make a function to obtain these info...
@@ -190,7 +187,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
190
187
dstHex := exportPath .Join (exportFile + ext )
191
188
logrus .WithField ("from" , srcHex ).WithField ("to" , dstHex ).Print ("copying sketch build output" )
192
189
if err = srcHex .CopyTo (dstHex ); err != nil {
193
- return nil , status .Errorf (codes . Internal , "Error copying output file: %s" , err )
190
+ return nil , fmt .Errorf (" copying output file: %s" , err )
194
191
}
195
192
196
193
// Copy .elf file to sketch directory
@@ -199,7 +196,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error)
199
196
logrus .WithField ("from" , srcElf ).WithField ("to" , dstElf ).Print ("copying sketch build output" )
200
197
if err = srcElf .CopyTo (dstElf ); err != nil {
201
198
formatter .PrintError (err , "Error copying elf file." )
202
- return nil , status .Errorf (codes . Internal , "Error copying elf file: %s" , err )
199
+ return nil , fmt .Errorf (" copying elf file: %s" , err )
203
200
}
204
201
205
202
return & rpc.CompileResp {}, nil
0 commit comments