Improve error handling and reporting for server installation & process boot

This commit is contained in:
Dane Everitt
2021-03-03 20:56:18 -08:00
parent 33f5cb7df4
commit 0919fb2da6
7 changed files with 38 additions and 29 deletions

View File

@@ -45,21 +45,21 @@ func New(ctx context.Context, manager *server.Manager, data []byte) (*Installer,
// Unmarshal the environment variables from the request into the server struct.
if b, _, _, err := jsonparser.Get(data, "environment"); err != nil {
return nil, err
return nil, errors.WithStackIf(err)
} else {
cfg.EnvVars = make(environment.Variables)
if err := json.Unmarshal(b, &cfg.EnvVars); err != nil {
return nil, err
return nil, errors.WrapIf(err, "installer: could not unmarshal environment variables for server")
}
}
// Unmarshal the allocation mappings from the request into the server struct.
if b, _, _, err := jsonparser.Get(data, "allocations", "mappings"); err != nil {
return nil, err
return nil, errors.WithStackIf(err)
} else {
cfg.Allocations.Mappings = make(map[string][]int)
if err := json.Unmarshal(b, &cfg.Allocations.Mappings); err != nil {
return nil, err
return nil, errors.Wrap(err, "installer: could not unmarshal allocation mappings")
}
}
@@ -68,16 +68,18 @@ func New(ctx context.Context, manager *server.Manager, data []byte) (*Installer,
c, err := manager.Client().GetServerConfiguration(ctx, cfg.Uuid)
if err != nil {
if !remote.IsRequestError(err) {
return nil, err
return nil, errors.WithStackIf(err)
}
return nil, errors.New(err.Error())
return nil, errors.WrapIf(err, "installer: could not get server configuration from remote API")
}
// Create a new server instance using the configuration we wrote to the disk
// so that everything gets instantiated correctly on the struct.
s, err := manager.InitServer(c)
return &Installer{server: s}, err
if err != nil {
return nil, errors.WrapIf(err, "installer: could not init server instance")
}
return &Installer{server: s}, nil
}
// Uuid returns the UUID associated with this installer instance.