Skip to content

Commit

Permalink
Avoid crash on useless config parameters (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Nov 28, 2024
1 parent 2fa2ca6 commit 3e0b204
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion NBXplorer/Configuration/ExplorerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ public ExplorerConfiguration LoadArgs(IConfiguration config)
RabbitMqPassword = config.GetOrDefault<string>("rmqpass", "");
RabbitMqTransactionExchange = config.GetOrDefault<string>("rmqtranex", "");
RabbitMqBlockExchange = config.GetOrDefault<string>("rmqblockex", "");

var obsolete = string.Join(", ",
new[] { "dbtrie", "automigrate", "nomigrateevts", "nomigraterawtxs", "cachechain", "deleteaftermigration", "dbcache" }
.Where(o => config.GetOrDefault<bool>(o, false)));
.Where(o => TryGetOrDefault<bool>(config, o, false)));

if (obsolete != string.Empty)
{
Expand All @@ -215,6 +216,18 @@ public ExplorerConfiguration LoadArgs(IConfiguration config)
return this;
}

private T TryGetOrDefault<T>(IConfiguration conf, string key, T defaultValue)
{
try
{
return conf.GetOrDefault<T>(key, defaultValue);
}
catch
{
return defaultValue;
}
}

private int GetPort(EndPoint nodeEndpoint)
{
if (nodeEndpoint is IPEndPoint endPoint)
Expand Down

0 comments on commit 3e0b204

Please sign in to comment.