Skip to content

Commit 486e359

Browse files
Fixing JSON marshaling of large numbers during migration
- Added some context to an error message - it's useful to know _which_ plugin failed when invoking the binary failed - Replaced `json.Umarshal` with a `json.Decoder`, so that the `UseNumber` function can be called, which prevents large integers from being interpreted as `float64`s. - Fixed a couple `log.Warn` calls that should've been `log.Warnf` Signed-off-by: Dave Henderson <dhenderson@gmail.com>
1 parent b818d3f commit 486e359

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

commands/commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func listHosts(store persist.Store) ([]*host.Host, error) {
113113
for _, h := range hosts {
114114
d, err := newPluginDriver(h.DriverName, h.RawDriver)
115115
if err != nil {
116-
return nil, fmt.Errorf("Error attempting to invoke binary for plugin: %s", err)
116+
return nil, fmt.Errorf("Error attempting to invoke binary for plugin '%s': %s", h.DriverName, err)
117117
}
118118

119119
h.Driver = d

libmachine/host/migrate_v2_v3.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package host
22

33
import (
4+
"bytes"
45
"encoding/json"
56

67
"github.com/docker/machine/libmachine/log"
@@ -22,7 +23,9 @@ func MigrateHostV2ToHostV3(hostV2 *HostV2, data []byte, storePath string) *Host
2223

2324
// Must migrate to include store path in driver since it was not
2425
// previously stored in drivers directly
25-
if err := json.Unmarshal(*rawHost.Driver, &m); err != nil {
26+
d := json.NewDecoder(bytes.NewReader(*rawHost.Driver))
27+
d.UseNumber()
28+
if err := d.Decode(&m); err != nil {
2629
log.Warnf("Could not unmarshal raw host into map[string]interface{}: %s", err)
2730
}
2831

0 commit comments

Comments
 (0)