From b3d4b466aa54fd108cc1177ab6c7c60b8b90e85b Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Tue, 19 Feb 2019 00:00:00 +0800 Subject: [PATCH] Don't print stack trace to console for invalid config files --- src/Core/ServiceWrapper/Main.cs | 7 +++++++ src/Core/WinSWCore/ServiceDescriptor.cs | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index d15e0dd..e035663 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -455,6 +455,13 @@ namespace winsw Log.Debug("Completed. Exit code is 0"); return 0; } + catch (InvalidDataException e) + { + string message = "The configuration file cound not be loaded. " + e.Message; + Log.Fatal(message, e); + Console.Error.WriteLine(message); + return -1; + } catch (WmiException e) { Log.Fatal("WMI Operation failure: " + e.ErrorCode, e); diff --git a/src/Core/WinSWCore/ServiceDescriptor.cs b/src/Core/WinSWCore/ServiceDescriptor.cs index 511dbb8..bcaf140 100755 --- a/src/Core/WinSWCore/ServiceDescriptor.cs +++ b/src/Core/WinSWCore/ServiceDescriptor.cs @@ -63,7 +63,14 @@ namespace winsw BaseName = baseName; BasePath = Path.Combine(d.FullName, BaseName); - dom.Load(BasePath + ".xml"); + try + { + dom.Load(BasePath + ".xml"); + } + catch (XmlException e) + { + throw new InvalidDataException(e.Message, e); + } // register the base directory as environment variable so that future expansions can refer to this. Environment.SetEnvironmentVariable("BASE", d.FullName);