mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
fix(crashes): trying to investigate the causes of crash.
New unit tests to that end.
This commit is contained in:
@@ -305,10 +305,31 @@ func init() {
|
||||
var err error
|
||||
ErupeConfig, err = LoadConfig()
|
||||
if err != nil {
|
||||
preventClose(fmt.Sprintf("Failed to load config: %s", err.Error()))
|
||||
// In test environments or when config.toml is missing, use defaults
|
||||
ErupeConfig = &Config{
|
||||
ClientMode: "ZZ",
|
||||
RealClientMode: ZZ,
|
||||
}
|
||||
// Only call preventClose if it's not a test environment
|
||||
if !isTestEnvironment() {
|
||||
preventClose(fmt.Sprintf("Failed to load config: %s", err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isTestEnvironment() bool {
|
||||
// Check if we're running under test
|
||||
for _, arg := range os.Args {
|
||||
if arg == "-test.v" || arg == "-test.run" || arg == "-test.timeout" {
|
||||
return true
|
||||
}
|
||||
if strings.Contains(arg, "test") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getOutboundIP4 gets the preferred outbound ip4 of this machine
|
||||
// From https://stackoverflow.com/a/37382208
|
||||
func getOutboundIP4() net.IP {
|
||||
@@ -370,7 +391,7 @@ func LoadConfig() (*Config, error) {
|
||||
}
|
||||
|
||||
func preventClose(text string) {
|
||||
if ErupeConfig.DisableSoftCrash {
|
||||
if ErupeConfig != nil && ErupeConfig.DisableSoftCrash {
|
||||
os.Exit(0)
|
||||
}
|
||||
fmt.Println("\nFailed to start Erupe:\n" + text)
|
||||
|
||||
Reference in New Issue
Block a user