Skip to content

Commit

Permalink
Do not print stack trace when invalid configuration is encountered
Browse files Browse the repository at this point in the history
- This improves invalid configuration output and makes it easier to spot
what the actual issue is.
- This also ensures that an invalid configuration is seen as a graceful
shutdown rather than the server terminating unexpectedly.
  • Loading branch information
pgermishuys committed Jun 30, 2020
1 parent b3e6053 commit 326c1f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/EventStore.ClusterNode/ClusterVNodeHostedService.cs
Expand Up @@ -151,12 +151,12 @@ internal class ClusterVNodeHostedService : EventStoreHostedService<ClusterNodeOp

_dbLock = new ExclusiveDbLock(absolutePath);
if (!_dbLock.Acquire())
throw new Exception($"Couldn't acquire exclusive lock on DB at '{dbPath}'.");
throw new InvalidConfigurationException($"Couldn't acquire exclusive lock on DB at '{dbPath}'.");
}

_clusterNodeMutex = new ClusterNodeMutex();
if (!_clusterNodeMutex.Acquire())
throw new Exception($"Couldn't acquire exclusive Cluster Node mutex '{_clusterNodeMutex.MutexName}'.");
throw new InvalidConfigurationException($"Couldn't acquire exclusive Cluster Node mutex '{_clusterNodeMutex.MutexName}'.");

if (!opts.DiscoverViaDns && opts.GossipSeed.Length == 0) {
if (opts.ClusterSize == 1) {
Expand Down Expand Up @@ -216,7 +216,7 @@ internal class ClusterVNodeHostedService : EventStoreHostedService<ClusterNodeOp
Log.Information("Quorum size set to {quorum}", prepareCount);

if (options.ReadOnlyReplica && options.ClusterSize <= 1) {
throw new Exception(
throw new InvalidConfigurationException(
"This node cannot be configured as a Read Only Replica as these node types are only supported in a clustered configuration.");
}

Expand Down Expand Up @@ -368,7 +368,7 @@ internal class ClusterVNodeHostedService : EventStoreHostedService<ClusterNodeOp
options.CertificatePrivateKeyFile,
options.CertificatePassword);
} else if (!options.Dev)
throw new Exception("A TLS Certificate is required unless development mode (--dev) is set.");
throw new InvalidConfigurationException("A TLS Certificate is required unless development mode (--dev) is set.");

var authorizationConfig = String.IsNullOrEmpty(options.AuthorizationConfig)
? options.Config
Expand All @@ -377,7 +377,7 @@ internal class ClusterVNodeHostedService : EventStoreHostedService<ClusterNodeOp
if (!string.IsNullOrEmpty(options.TrustedRootCertificatesPath)) {
builder.WithTrustedRootCertificatesPath(options.TrustedRootCertificatesPath);
} else {
throw new Exception(
throw new InvalidConfigurationException(
$"{nameof(options.TrustedRootCertificatesPath)} must be specified unless development mode (--dev) is set.");
}

Expand Down
@@ -0,0 +1,7 @@
using System;

namespace EventStore.Common.Exceptions {
public class InvalidConfigurationException : Exception {
public InvalidConfigurationException(string message) : base(message) { }
}
}
15 changes: 9 additions & 6 deletions src/EventStore.Core/EventStoreHostedService.cs
Expand Up @@ -43,12 +43,15 @@ public abstract class EventStoreHostedService<TOptions> : IHostedService where T
Create(Options);
}
} catch (OptionException exc) {
Console.Error.WriteLine("Error while parsing options:");
Console.Error.WriteLine(FormatExceptionMessage(exc));
Console.Error.WriteLine();
Console.Error.WriteLine("Options:");
Console.Error.WriteLine(EventStoreOptions.GetUsage<TOptions>());
throw;
Log.Error("Error while parsing options:");
Log.Error(FormatExceptionMessage(exc));
Log.Information("Options:");
Log.Information(EventStoreOptions.GetUsage<TOptions>());
_skipRun = true;
} catch (InvalidConfigurationException exc) {
Log.Error("Invalid Configuration Encountered");
Log.Error(exc.Message);
_skipRun = true;
}
}

Expand Down

0 comments on commit 326c1f4

Please sign in to comment.