Skip to content

Commit c4e3480

Browse files
committed
Extract const for simple errors
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
1 parent 6940dc3 commit c4e3480

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/amazonec2/amazonec2.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ const (
4747
)
4848

4949
var (
50-
dockerPort = 2376
51-
swarmPort = 3376
50+
dockerPort = 2376
51+
swarmPort = 3376
52+
errorMissingAccessKeyOption = errors.New("amazonec2 driver requires the --amazonec2-access-key option")
53+
errorMissingSecretKeyOption = errors.New("amazonec2 driver requires the --amazonec2-secret-key option")
54+
errorNoVPCIdFound = errors.New("amazonec2 driver requires either the --amazonec2-subnet-id or --amazonec2-vpc-id option or an AWS Account with a default vpc-id")
5255
)
5356

5457
type Driver struct {
@@ -282,22 +285,22 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
282285
d.SetSwarmConfigFromFlags(flags)
283286

284287
if d.AccessKey == "" {
285-
return fmt.Errorf("amazonec2 driver requires the --amazonec2-access-key option")
288+
return errorMissingAccessKeyOption
286289
}
287290

288291
if d.SecretKey == "" {
289-
return fmt.Errorf("amazonec2 driver requires the --amazonec2-secret-key option")
292+
return errorMissingSecretKeyOption
290293
}
291294

292295
if d.VpcId == "" {
293296
d.VpcId, err = d.getDefaultVPCId()
294297
if err != nil {
295-
log.Errorf("couldn't determine your account Default VPC ID : %q", err)
298+
log.Warnf("Couldn't determine your account Default VPC ID : %q", err)
296299
}
297300
}
298301

299302
if d.SubnetId == "" && d.VpcId == "" {
300-
return fmt.Errorf("amazonec2 driver requires either the --amazonec2-subnet-id or --amazonec2-vpc-id option or an AWS Account with a default vpc-id")
303+
return errorNoVPCIdFound
301304
}
302305

303306
if d.SubnetId != "" && d.VpcId != "" {

0 commit comments

Comments
 (0)