@@ -21,7 +21,10 @@ func (d *Driver) getLocation() (*hcloud.Location, error) {
2121
2222 location , _ , err := d .getClient ().Location .GetByName (context .Background (), d .Location )
2323 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 )
2528 }
2629 d .cachedLocation = location
2730 return location , nil
@@ -34,7 +37,10 @@ func (d *Driver) getType() (*hcloud.ServerType, error) {
3437
3538 stype , _ , err := d .getClient ().ServerType .GetByName (context .Background (), d .Type )
3639 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 )
3844 }
3945 d .cachedType = stype
4046 return instrumented (stype ), nil
@@ -51,7 +57,10 @@ func (d *Driver) getImage() (*hcloud.Image, error) {
5157 if d .ImageID != 0 {
5258 image , _ , err = d .getClient ().Image .GetByID (context .Background (), d .ImageID )
5359 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 )
5564 }
5665 } else {
5766 arch , err := d .getImageArchitectureForLookup ()
@@ -61,7 +70,10 @@ func (d *Driver) getImage() (*hcloud.Image, error) {
6170
6271 image , _ , err = d .getClient ().Image .GetByNameAndArchitecture (context .Background (), d .Image , arch )
6372 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 )
6577 }
6678 }
6779
@@ -87,12 +99,15 @@ func (d *Driver) getKey() (*hcloud.SSHKey, error) {
8799 return d .cachedKey , nil
88100 }
89101
90- stype , _ , err := d .getClient ().SSHKey .GetByID (context .Background (), d .KeyID )
102+ key , _ , err := d .getClient ().SSHKey .GetByID (context .Background (), d .KeyID )
91103 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" )
93105 }
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
96111}
97112
98113func (d * Driver ) getRemoteKeyWithSameFingerprint (publicKeyBytes []byte ) (* hcloud.SSHKey , error ) {
@@ -107,10 +122,24 @@ func (d *Driver) getRemoteKeyWithSameFingerprint(publicKeyBytes []byte) (*hcloud
107122 if err != nil {
108123 return remoteKey , errors .Wrap (err , "could not get sshkey by fingerprint" )
109124 }
125+ if remoteKey == nil {
126+ return nil , fmt .Errorf ("key not found by fingerprint: %v" , fp )
127+ }
110128 return instrumented (remoteKey ), nil
111129}
112130
113131func (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 ) {
114143 if d .cachedServer != nil {
115144 return d .cachedServer , nil
116145 }
@@ -134,6 +163,9 @@ func (d *Driver) waitForAction(a *hcloud.Action) error {
134163 if err != nil {
135164 return errors .Wrap (err , "could not get client by ID" )
136165 }
166+ if act == nil {
167+ return fmt .Errorf ("action not found: %v" , a .ID )
168+ }
137169
138170 if act .Status == hcloud .ActionStatusSuccess {
139171 log .Debugf (" -> finished %s[%d]" , act .Command , act .ID )
0 commit comments