Improve error handling and reporting for server installation & process boot
This commit is contained in:
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"emperror.dev/errors"
|
||||
"github.com/buger/jsonparser"
|
||||
@@ -9,24 +10,25 @@ import (
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
)
|
||||
|
||||
// Merges data passed through in JSON form into the existing server object.
|
||||
// Any changes to the build settings will apply immediately in the environment
|
||||
// if the environment supports it.
|
||||
// UpdateDataStructure merges data passed through in JSON form into the existing
|
||||
// server object. Any changes to the build settings will apply immediately in
|
||||
// the environment if the environment supports it.
|
||||
//
|
||||
// The server will be marked as requiring a rebuild on the next boot sequence,
|
||||
// it is up to the specific environment to determine what needs to happen when
|
||||
// that is the case.
|
||||
func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
src := new(Configuration)
|
||||
fmt.Println("got data", string(data))
|
||||
if err := json.Unmarshal(data, src); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "server/update: could not unmarshal source data into Configuration struct")
|
||||
}
|
||||
|
||||
// Don't allow obviously corrupted data to pass through into this function. If the UUID
|
||||
// doesn't match something has gone wrong and the API is attempting to meld this server
|
||||
// instance into a totally different one, which would be bad.
|
||||
if src.Uuid != "" && s.Id() != "" && src.Uuid != s.Id() {
|
||||
return errors.New("attempting to merge a data stack with an invalid UUID")
|
||||
return errors.New("server/update: attempting to merge a data stack with an invalid UUID")
|
||||
}
|
||||
|
||||
// Grab a copy of the configuration to work on.
|
||||
@@ -48,7 +50,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// Merge the new data object that we have received with the existing server data object
|
||||
// and then save it to the disk so it is persistent.
|
||||
if err := mergo.Merge(&c, src, mergo.WithOverride); err != nil {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
// Don't explode if we're setting CPU limits to 0. Mergo sees that as an empty value
|
||||
@@ -62,7 +64,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// request is going to be boolean. Allegedly.
|
||||
if v, err := jsonparser.GetBoolean(data, "container", "oom_disabled"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
} else {
|
||||
c.Build.OOMDisabled = v
|
||||
@@ -71,7 +73,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// Mergo also cannot handle this boolean value.
|
||||
if v, err := jsonparser.GetBoolean(data, "suspended"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
} else {
|
||||
c.Suspended = v
|
||||
@@ -79,7 +81,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
|
||||
if v, err := jsonparser.GetBoolean(data, "skip_egg_scripts"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return err
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
} else {
|
||||
c.SkipEggScripts = v
|
||||
|
||||
Reference in New Issue
Block a user