|
13 | 13 | using Azure.DataApiBuilder.Product; |
14 | 14 | using Azure.DataApiBuilder.Service.Exceptions; |
15 | 15 | using Microsoft.Data.SqlClient; |
16 | | -using Microsoft.Extensions.Logging; |
17 | 16 | using Microsoft.Extensions.Primitives; |
18 | 17 | using Npgsql; |
19 | 18 | using static Azure.DataApiBuilder.Config.DabConfigEvents; |
@@ -179,16 +178,34 @@ protected void SignalConfigChanged(string message = "") |
179 | 178 | /// </summary> |
180 | 179 | /// <param name="json">JSON that represents the config file.</param> |
181 | 180 | /// <param name="config">The parsed config, or null if it parsed unsuccessfully.</param> |
| 181 | + /// <param name="parseError">A clean error message when parsing fails, or null on success.</param> |
182 | 182 | /// <param name="replacementSettings">Settings for variable replacement during deserialization. If null, no variable replacement will be performed.</param> |
183 | | - /// <param name="logger">logger to log messages</param> |
184 | 183 | /// <param name="connectionString">connectionString to add to config if specified</param> |
185 | 184 | /// <returns>True if the config was parsed, otherwise false.</returns> |
186 | 185 | public static bool TryParseConfig(string json, |
187 | 186 | [NotNullWhen(true)] out RuntimeConfig? config, |
188 | 187 | DeserializationVariableReplacementSettings? replacementSettings = null, |
189 | | - ILogger? logger = null, |
190 | 188 | string? connectionString = null) |
191 | 189 | { |
| 190 | + return TryParseConfig(json, out config, out _, replacementSettings, connectionString); |
| 191 | + } |
| 192 | + |
| 193 | + /// <summary> |
| 194 | + /// Parses a JSON string into a <c>RuntimeConfig</c> object for single database scenario. |
| 195 | + /// </summary> |
| 196 | + /// <param name="json">JSON that represents the config file.</param> |
| 197 | + /// <param name="config">The parsed config, or null if it parsed unsuccessfully.</param> |
| 198 | + /// <param name="parseError">A clean error message when parsing fails, or null on success.</param> |
| 199 | + /// <param name="replacementSettings">Settings for variable replacement during deserialization. If null, no variable replacement will be performed.</param> |
| 200 | + /// <param name="connectionString">connectionString to add to config if specified</param> |
| 201 | + /// <returns>True if the config was parsed, otherwise false.</returns> |
| 202 | + public static bool TryParseConfig(string json, |
| 203 | + [NotNullWhen(true)] out RuntimeConfig? config, |
| 204 | + out string? parseError, |
| 205 | + DeserializationVariableReplacementSettings? replacementSettings = null, |
| 206 | + string? connectionString = null) |
| 207 | + { |
| 208 | + parseError = null; |
192 | 209 | // First pass: extract AzureKeyVault options if AKV replacement is requested |
193 | 210 | if (replacementSettings?.DoReplaceAkvVar is true) |
194 | 211 | { |
@@ -263,18 +280,9 @@ public static bool TryParseConfig(string json, |
263 | 280 | ex is JsonException || |
264 | 281 | ex is DataApiBuilderException) |
265 | 282 | { |
266 | | - string errorMessage = ex is JsonException ? "Deserialization of the configuration file failed." : |
267 | | - "Deserialization of the configuration file failed during a post-processing step."; |
268 | | - |
269 | | - // logger can be null when called from CLI |
270 | | - if (logger is null) |
271 | | - { |
272 | | - Console.Error.WriteLine(errorMessage + $"\n" + $"Message:\n {ex.Message}\n" + $"Stack Trace:\n {ex.StackTrace}"); |
273 | | - } |
274 | | - else |
275 | | - { |
276 | | - logger.LogError(exception: ex, message: errorMessage); |
277 | | - } |
| 283 | + parseError = ex is DataApiBuilderException |
| 284 | + ? ex.Message |
| 285 | + : $"Deserialization of the configuration file failed. {ex.Message}"; |
278 | 286 |
|
279 | 287 | config = null; |
280 | 288 | return false; |
|
0 commit comments