Skip to content

Fix dab validate error messaging when logger is not available#3311

Open
aaronburtle wants to merge 16 commits intomainfrom
dev/aaronburtle/fix-schema-validation-no-entities
Open

Fix dab validate error messaging when logger is not available#3311
aaronburtle wants to merge 16 commits intomainfrom
dev/aaronburtle/fix-schema-validation-no-entities

Conversation

@aaronburtle
Copy link
Copy Markdown
Contributor

@aaronburtle aaronburtle commented Mar 24, 2026

Why make this change?

Closes #3268

What is this change?

When dab validate or dab start encounters a config parsing error (e.g. missing entities/autoentities), the CLI previously dumped the full exception message and stack trace to stderr. This made the output noisy and unhelpful. After this change, only a clean, descriptive validation message is shown.

The key design changes:

  • TryParseConfig is now a pure function that returns an out string? parseError message on failure instead of writing to Console.Error or ILogger internally. Error reporting is the caller's responsibility.
  • FileSystemRuntimeConfigLoader.TryLoadConfig writes the parseError to Console.Error (because config is parsed before the DI container and logger are available, so the log buffer would never be flushed on a parse failure) and sets an instance-scoped IsParseErrorEmitted flag so CLI callers (ConfigGenerator) can avoid logging duplicate messages.
  • ConfigGenerator.IsConfigValid now has an explicit early-return path when config parsing fails (via runtimeConfigProvider.TryGetConfig), using IsParseErrorEmitted to suppress duplicate output.
  • ValidateOptions.Handler uses LogError("Config is invalid.").
  • Comments referencing which method emits the error to Console.Error corrected to TryLoadConfig (not TryParseConfig).

How was this tested?

  • ValidateConfigTests.cs — Added TestValidateConfigWithNoEntitiesProducesCleanError (new test verifying clean error message, no stack traces).
  • EnvironmentTests.cs — Updated FailureToStartEngineWhenEnvVarNamedWrong to match the new single-line clean stderr format.
  • EndToEndTests.cs — Simplified assertions in TestExitOfRuntimeEngineWithInvalidConfig (this test is Ignored but updated for consistency).
  • RuntimeConfigLoaderTests.cs — Updated FailLoadMultiDataSourceConfigDuplicateEntities to assert loader.IsParseErrorEmitted is true.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the CLI experience for dab validate / dab start when config parsing fails by surfacing a clean, user-focused error message (instead of dumping exception details/stack traces), and updates tests to match the new output.

Changes:

  • Add a mechanism (RuntimeConfigLoader.LastParseError) to capture the last config parse error message for callers (CLI) to display cleanly.
  • Update CLI config loading/validation paths to log the captured parse error and (for validate) suppress raw Console.Error output during config loading.
  • Update CLI and service/CLI tests to assert the new single-line/clean error behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Config/RuntimeConfigLoader.cs Captures last parse error and changes exception handling output/logging behavior.
src/Cli/ConfigGenerator.cs Uses LastParseError when config load fails; suppresses Console.Error during validation config load.
src/Cli/Commands/ValidateOptions.cs Changes “Config is invalid” message severity/output format.
src/Cli.Tests/ValidateConfigTests.cs Adds regression coverage ensuring clean error messages (no stack traces) for missing entities/autoentities.
src/Cli.Tests/EnvironmentTests.cs Updates stderr assertions for new clean error format.
src/Cli.Tests/EndToEndTests.cs Removes outdated assertions in ignored test to align with new behavior.
src/Service.Tests/Configuration/RuntimeConfigLoaderTests.cs Updates assertions to validate clean error output without stack traces.

@aaronburtle aaronburtle self-assigned this Mar 25, 2026
@aaronburtle aaronburtle added 2.0 cleanup bug Something isn't working labels Mar 25, 2026
@aaronburtle aaronburtle moved this from Todo to Review In Progress in Data API builder Mar 25, 2026
@aaronburtle aaronburtle added this to the March 2026 milestone Mar 25, 2026
@aaronburtle
Copy link
Copy Markdown
Contributor Author

@copilot can you do another PR review please.

Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Azure/data-api-builder/sessions/5aec902b-92d0-4b71-ba4b-32ca2c049908
Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

@copilot can you do another PR review please.

Review complete. The refactoring looks solid — all previous concerns are addressed. I found and fixed two small issues in commit 2b953b4:

  1. ValidateOptions.Handler: The summary message on validation failure was changed to LogInformation("Config is invalid."), which rendered with a green "Information:" prefix — misleading for a failure. Restored to LogError("Config is invalid.") for a clear red "Error:" prefix consistent with other failure paths.

  2. Comment accuracy in ConfigGenerator.cs: Two comments said "TryParseConfig already emitted the detailed error to Console.Error" but it's TryLoadConfig that calls Console.Error.WriteLine. Corrected to "TryLoadConfig already emitted".

Copy link
Copy Markdown
Contributor

@souvikghosh04 souvikghosh04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posting comments so far

using System.IO.Abstractions;
using System.Net;
using System.Net.Http;
using System.Text.Json;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file/test being deleted?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaked from another branch during a local merge. Not related to this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are now actually deleting this from main as well if I approve and merge this PR. Is this what you intend? Is there another PR that will add it back to main?

Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on merge with #3318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 bug Something isn't working cleanup

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: Schema validation fail in dab config throws exception

6 participants