@@ -19,6 +19,7 @@ package cmd
19
19
import (
20
20
"bytes"
21
21
"embed"
22
+ "errors"
22
23
"fmt"
23
24
"html/template"
24
25
"io"
@@ -29,7 +30,6 @@ import (
29
30
"strings"
30
31
"time"
31
32
32
- "github.com/pkg/errors"
33
33
"github.com/sirupsen/logrus"
34
34
"github.com/spf13/cobra"
35
35
@@ -159,26 +159,26 @@ func initLogging(*cobra.Command, []string) error {
159
159
160
160
func run (opts * options ) error {
161
161
if err := opts .SetAndValidate (); err != nil {
162
- return errors . Wrap ( err , "validating schedule-path options" )
162
+ return fmt . Errorf ( "validating schedule-path options: %w" , err )
163
163
}
164
164
165
165
if opts .sendgridAPIKey == "" {
166
- return errors .Errorf (
166
+ return fmt .Errorf (
167
167
"$%s is not set" , sendgridAPIKeyEnvKey ,
168
168
)
169
169
}
170
170
171
171
data , err := loadFileOrURL (opts .schedulePath )
172
172
if err != nil {
173
- return errors . Wrap ( err , "failed to read the file" )
173
+ return fmt . Errorf ( "failed to read the file: %w" , err )
174
174
}
175
175
176
176
patchSchedule := & model.PatchSchedule {}
177
177
178
178
logrus .Info ("Parsing the schedule..." )
179
179
180
180
if err := yaml .UnmarshalStrict (data , & patchSchedule ); err != nil {
181
- return errors . Wrap ( err , "failed to decode the file" )
181
+ return fmt . Errorf ( "failed to decode the file: %w" , err )
182
182
}
183
183
184
184
output := & Template {}
@@ -188,7 +188,7 @@ func run(opts *options) error {
188
188
for _ , patch := range patchSchedule .Schedules {
189
189
t , err := time .Parse (layout , patch .CherryPickDeadline )
190
190
if err != nil {
191
- return errors . Wrap ( err , "parsing schedule time" )
191
+ return fmt . Errorf ( "parsing schedule time: %w" , err )
192
192
}
193
193
194
194
currentTime := time .Now ().UTC ()
@@ -205,13 +205,13 @@ func run(opts *options) error {
205
205
206
206
tmpl , err := template .ParseFS (tpls , "templates/email.tmpl" )
207
207
if err != nil {
208
- return errors . Wrap ( err , "parsing template" )
208
+ return fmt . Errorf ( "parsing template: %w" , err )
209
209
}
210
210
211
211
var tmplBytes bytes.Buffer
212
212
err = tmpl .Execute (& tmplBytes , output )
213
213
if err != nil {
214
- return errors . Wrap ( err , "parsing values to the template" )
214
+ return fmt . Errorf ( "parsing values to the template: %w" , err )
215
215
}
216
216
217
217
if shouldSendEmail {
@@ -225,12 +225,12 @@ func run(opts *options) error {
225
225
226
226
if opts .name != "" && opts .email != "" {
227
227
if err := m .SetSender (opts .name , opts .email ); err != nil {
228
- return errors . Wrap ( err , "unable to set mail sender" )
228
+ return fmt . Errorf ( "unable to set mail sender: %w" , err )
229
229
}
230
230
} else {
231
231
logrus .Info ("Retrieving default sender from sendgrid API" )
232
232
if err := m .SetDefaultSender (); err != nil {
233
- return errors . Wrap ( err , "setting default sender" )
233
+ return fmt . Errorf ( "setting default sender: %w" , err )
234
234
}
235
235
}
236
236
@@ -243,14 +243,14 @@ func run(opts *options) error {
243
243
logrus .Infof ("Using Google Groups as announcement target: %v" , groups )
244
244
245
245
if err := m .SetGoogleGroupRecipients (groups ... ); err != nil {
246
- return errors . Wrap ( err , "unable to set mail recipients" )
246
+ return fmt . Errorf ( "unable to set mail recipients: %w" , err )
247
247
}
248
248
249
249
logrus .Info ("Sending mail" )
250
250
subject := "[Please Read] Patch Releases cherry-pick deadline"
251
251
252
252
if err := m .Send (tmplBytes .String (), subject ); err != nil {
253
- return errors . Wrap ( err , "unable to send mail" )
253
+ return fmt . Errorf ( "unable to send mail: %w" , err )
254
254
}
255
255
} else {
256
256
logrus .Info ("No email is needed to send" )
@@ -264,7 +264,7 @@ func (o *options) SetAndValidate() error {
264
264
logrus .Info ("Validating schedule-path options..." )
265
265
266
266
if o .schedulePath == "" {
267
- return errors .Errorf ("need to set the schedule-path" )
267
+ return errors .New ("need to set the schedule-path" )
268
268
}
269
269
270
270
return nil
0 commit comments