avoid panic crash due to bad environment variable values; closes pterodactyl/panel#2275

This commit is contained in:
Dane Everitt 2020-08-27 20:05:07 -07:00
parent 0dde54fc8f
commit 60acee2df5
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -2,6 +2,7 @@ package environment
import (
"fmt"
"github.com/apex/log"
"math"
"strconv"
)
@ -118,7 +119,13 @@ func (v Variables) Get(key string) string {
return fmt.Sprintf("%f", val.(float64))
case bool:
return strconv.FormatBool(val.(bool))
}
case string:
return val.(string)
}
// TODO: I think we can add a check for val == nil and return an empty string for those
// and this warning should theoretically never happen?
log.Warn(fmt.Sprintf("failed to marshal environment variable \"%s\" of type %+v into string", key, val))
return ""
}