forked from JonasProgrammer/docker-machine-driver-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag_failure_debug.go
32 lines (25 loc) · 942 Bytes
/
flag_failure_debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build flag_debug || instrumented
package main
import (
"encoding/json"
"fmt"
"github.com/docker/machine/libmachine/drivers"
"github.com/pkg/errors"
)
var lastOpts drivers.DriverOptions
func (d *Driver) flagFailure(format string, args ...interface{}) error {
// machine driver may not flush logs received when getting an RPC error, so we have to resort to this terribleness
line1 := fmt.Sprintf("Flag failure detected:\n -> last opts: %v\n -> driver state %v", lastOpts, d)
var line2 string
if out, err := json.MarshalIndent(d, "", " "); err == nil {
line2 = fmt.Sprintf(" -> driver json:\n%s", out)
} else {
line2 = fmt.Sprintf("could not encode driver json: %v", err)
}
combined := append([]interface{}{line1, line2}, args...)
return errors.Errorf("%s\n%s\n"+format, combined...)
}
func (d *Driver) setConfigFromFlags(opts drivers.DriverOptions) error {
lastOpts = opts
return d.setConfigFromFlagsImpl(opts)
}