@@ -21,7 +21,10 @@ func (d *Driver) getLocation() (*hcloud.Location, error) {
21
21
22
22
location , _ , err := d .getClient ().Location .GetByName (context .Background (), d .Location )
23
23
if err != nil {
24
- return location , errors .Wrap (err , "could not get location by name" )
24
+ return nil , errors .Wrap (err , "could not get location by name" )
25
+ }
26
+ if location == nil {
27
+ return nil , fmt .Errorf ("unknown location: %v" , d .Location )
25
28
}
26
29
d .cachedLocation = location
27
30
return location , nil
@@ -34,7 +37,10 @@ func (d *Driver) getType() (*hcloud.ServerType, error) {
34
37
35
38
stype , _ , err := d .getClient ().ServerType .GetByName (context .Background (), d .Type )
36
39
if err != nil {
37
- return stype , errors .Wrap (err , "could not get type by name" )
40
+ return nil , errors .Wrap (err , "could not get type by name" )
41
+ }
42
+ if stype == nil {
43
+ return nil , fmt .Errorf ("unknown server type: %v" , d .Type )
38
44
}
39
45
d .cachedType = stype
40
46
return instrumented (stype ), nil
@@ -51,7 +57,10 @@ func (d *Driver) getImage() (*hcloud.Image, error) {
51
57
if d .ImageID != 0 {
52
58
image , _ , err = d .getClient ().Image .GetByID (context .Background (), d .ImageID )
53
59
if err != nil {
54
- return image , errors .Wrap (err , fmt .Sprintf ("could not get image by id %v" , d .ImageID ))
60
+ return nil , errors .Wrap (err , fmt .Sprintf ("could not get image by id %v" , d .ImageID ))
61
+ }
62
+ if image == nil {
63
+ return nil , fmt .Errorf ("image id not found: %v" , d .ImageID )
55
64
}
56
65
} else {
57
66
arch , err := d .getImageArchitectureForLookup ()
@@ -61,7 +70,10 @@ func (d *Driver) getImage() (*hcloud.Image, error) {
61
70
62
71
image , _ , err = d .getClient ().Image .GetByNameAndArchitecture (context .Background (), d .Image , arch )
63
72
if err != nil {
64
- return image , errors .Wrap (err , fmt .Sprintf ("could not get image by name %v" , d .Image ))
73
+ return nil , errors .Wrap (err , fmt .Sprintf ("could not get image by name %v" , d .Image ))
74
+ }
75
+ if image == nil {
76
+ return nil , fmt .Errorf ("image not found: %v[%v]" , d .Image , arch )
65
77
}
66
78
}
67
79
@@ -87,12 +99,15 @@ func (d *Driver) getKey() (*hcloud.SSHKey, error) {
87
99
return d .cachedKey , nil
88
100
}
89
101
90
- stype , _ , err := d .getClient ().SSHKey .GetByID (context .Background (), d .KeyID )
102
+ key , _ , err := d .getClient ().SSHKey .GetByID (context .Background (), d .KeyID )
91
103
if err != nil {
92
- return stype , errors .Wrap (err , "could not get sshkey by ID" )
104
+ return nil , errors .Wrap (err , "could not get sshkey by ID" )
93
105
}
94
- d .cachedKey = stype
95
- return instrumented (stype ), nil
106
+ if key == nil {
107
+ return nil , fmt .Errorf ("key not found: %v" , d .KeyID )
108
+ }
109
+ d .cachedKey = key
110
+ return instrumented (key ), nil
96
111
}
97
112
98
113
func (d * Driver ) getRemoteKeyWithSameFingerprint (publicKeyBytes []byte ) (* hcloud.SSHKey , error ) {
@@ -107,10 +122,24 @@ func (d *Driver) getRemoteKeyWithSameFingerprint(publicKeyBytes []byte) (*hcloud
107
122
if err != nil {
108
123
return remoteKey , errors .Wrap (err , "could not get sshkey by fingerprint" )
109
124
}
125
+ if remoteKey == nil {
126
+ return nil , fmt .Errorf ("key not found by fingerprint: %v" , fp )
127
+ }
110
128
return instrumented (remoteKey ), nil
111
129
}
112
130
113
131
func (d * Driver ) getServerHandle () (* hcloud.Server , error ) {
132
+ srv , err := d .getServerHandleNullable ()
133
+ if err != nil {
134
+ return nil , err
135
+ }
136
+ if srv == nil {
137
+ return nil , fmt .Errorf ("server does not exist: %v" , d .ServerID )
138
+ }
139
+ return srv , nil
140
+ }
141
+
142
+ func (d * Driver ) getServerHandleNullable () (* hcloud.Server , error ) {
114
143
if d .cachedServer != nil {
115
144
return d .cachedServer , nil
116
145
}
@@ -134,6 +163,9 @@ func (d *Driver) waitForAction(a *hcloud.Action) error {
134
163
if err != nil {
135
164
return errors .Wrap (err , "could not get client by ID" )
136
165
}
166
+ if act == nil {
167
+ return fmt .Errorf ("action not found: %v" , a .ID )
168
+ }
137
169
138
170
if act .Status == hcloud .ActionStatusSuccess {
139
171
log .Debugf (" -> finished %s[%d]" , act .Command , act .ID )
0 commit comments