Skip to content

Conversation

@greghuels
Copy link
Collaborator

@greghuels greghuels commented Dec 2, 2025

Stacked onto #35

Summary

This PR introduces a new parseConfiguration() convenience function that provides comprehensive error feedback when parsing flag configurations and bandit models. The new API replaces the previous from_json pattern with explicit error tracking, making it easier to diagnose configuration issues.

What Changed

New Public API

Added parseConfiguration() convenience function with two overloads:

// Parse flags only
Configuration parseConfiguration(const std::string& flagConfigJson,
                                 std::string& error);

// Parse flags and bandit models together
Configuration parseConfiguration(const std::string& flagConfigJson,
                                 const std::string& banditModelsJson,
                                 std::string& error);

Key Features

  • Returns Configuration directly (no intermediate types needed)
  • Error messages via reference parameter with detailed diagnostics
  • Consolidates all parsing errors into a single formatted message
  • Optional bandit models support (pass empty string or use two-parameter overload)

Breaking Changes

  1. Replaced from_json with internal::parseBanditResponse
    - Old: BanditResponse response = json_object;
    - New: BanditResponse response = internal::parseBanditResponse(jsonStr, error);
    - Provides error tracking and better diagnostics
  2. Moved parsing functions to internal namespace
    - parseConfigResponse() → internal::parseConfigResponse()
    - parseBanditResponse() → internal::parseBanditResponse()
    - These are now implementation details; use parseConfiguration() instead

Migration Guide

Before:

 nlohmann::json flagsJson = nlohmann::json::parse(flagConfigJson);
 ConfigResponse flagConfig = flagsJson;

 nlohmann::json banditsJson = nlohmann::json::parse(banditModelsJson);
 BanditResponse banditModels = banditsJson;

After:

  std::string error;
  Configuration config = parseConfiguration(flagConfigJson, banditModelsJson, error);
  if (!error.empty()) {
      std::cerr << "Configuration error: " << error << std::endl;
      return 1;
  }

  Flags Only:
  std::string error;
  Configuration config = parseConfiguration(flagConfigJson, error);
  if (!error.empty()) {
      std::cerr << "Configuration error: " << error << std::endl;
      return 1;
  }

@greghuels greghuels force-pushed the greg.huels/error-feedback branch 2 times, most recently from c7f687c to 98d5a0b Compare December 2, 2025 11:53
@greghuels greghuels requested a review from dd-oleksii December 2, 2025 11:57
@greghuels greghuels marked this pull request as ready for review December 2, 2025 11:57
@greghuels greghuels force-pushed the greg.huels/FFESUPPORT-348/fix-end-date-parsing-2 branch from b76d870 to 639de63 Compare December 2, 2025 12:00
@greghuels greghuels force-pushed the greg.huels/error-feedback branch 2 times, most recently from f9149e7 to caa7519 Compare December 2, 2025 12:04
@greghuels greghuels force-pushed the greg.huels/FFESUPPORT-348/fix-end-date-parsing-2 branch from 639de63 to 6eace0c Compare December 2, 2025 12:32
@greghuels greghuels force-pushed the greg.huels/error-feedback branch from 982deb3 to 0e748da Compare December 2, 2025 12:32
@greghuels greghuels force-pushed the greg.huels/FFESUPPORT-348/fix-end-date-parsing-2 branch from 6eace0c to 930e0f7 Compare December 2, 2025 12:47
@greghuels greghuels force-pushed the greg.huels/error-feedback branch from 0e748da to f4dd0dd Compare December 2, 2025 12:47
@greghuels greghuels force-pushed the greg.huels/FFESUPPORT-348/fix-end-date-parsing-2 branch from 930e0f7 to 4aac24a Compare December 2, 2025 12:51
@greghuels greghuels force-pushed the greg.huels/error-feedback branch from f4dd0dd to a487779 Compare December 2, 2025 12:51
@greghuels greghuels force-pushed the greg.huels/FFESUPPORT-348/fix-end-date-parsing-2 branch from 4aac24a to fb3c196 Compare December 2, 2025 12:57
@greghuels greghuels force-pushed the greg.huels/error-feedback branch from a487779 to ad4b1d8 Compare December 2, 2025 12:59
@greghuels
Copy link
Collaborator Author

Closing since this is mostly captured in #40. I'll open a new PR for the parseConfiguration function

@greghuels greghuels closed this Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants