![]() |
OpenPFC
0.1.4
Phase Field Crystal simulation framework
|
Helpful error message formatting for JSON configuration validation. More...
#include <nlohmann/json.hpp>#include <sstream>#include <string>#include <vector>

Go to the source code of this file.
Functions | |
| std::string | pfc::ui::format_config_error (const std::string &field_name, const std::string &description, const std::string &expected_type, const std::string &actual_value, const std::vector< std::string > &valid_options={}, const std::string &example="") |
| Format a helpful configuration error message. | |
| std::string | pfc::ui::get_json_value_string (const nlohmann::json &j, const std::string &field_name) |
| Get JSON value as string for error messages. | |
| std::vector< std::string > | pfc::ui::list_valid_field_modifiers () |
| List all registered field modifiers. | |
| std::string | pfc::ui::format_unknown_modifier_error (const std::string &invalid_type, const std::string &context="field modifier") |
| Format error for unknown field modifier type. | |
Helpful error message formatting for JSON configuration validation.
This module provides utility functions for generating user-friendly error messages when JSON configuration validation fails. The functions format error messages with:
These helpers improve the user experience by making configuration errors immediately actionable, reducing debugging time and support burden.
|
inline |
Format a helpful configuration error message.
Creates a multi-line error message with complete context about a configuration validation failure. The message includes:
Error messages are designed to be:
| field_name | Name of problematic field (e.g., "Lx", "origo") |
| description | Human-readable description of field purpose |
| expected_type | Expected type with constraints (e.g., "positive integer") |
| actual_value | What user provided (use get_json_value_string()) |
| valid_options | List of valid values (empty if not applicable) |
| example | Working example syntax (empty if not needed) |
Time complexity: O(n) where n = number of valid_options


|
inline |
Format error for unknown field modifier type.
Creates a helpful error message when user specifies an unknown field modifier type in JSON configuration. Lists all valid types to help user correct the spelling or choose the right modifier.
| invalid_type | The type user tried to use |
| context | Context string (e.g., "field modifier", "initial condition") |
Time complexity: O(n) where n = number of registered field modifiers


|
inline |
Get JSON value as string for error messages.
Extracts the actual value from a JSON object and formats it for display in error messages. Returns "missing" if field doesn't exist, otherwise returns the JSON representation with type information.
Type information helps users understand type mismatches:
42 (type: integer)256.5 (type: float)"hello" (type: string)true (type: boolean)null (type: null)[1,2,3] (type: array){"key":"value"} (type: object)| j | JSON object to extract value from |
| field_name | Field name to look up |
Time complexity: O(n) where n = size of JSON value when dumping


| std::vector< std::string > pfc::ui::list_valid_field_modifiers | ( | ) |
List all registered field modifiers.
Returns a vector of all field modifier type names that can be used in JSON configuration. Includes both initial conditions and boundary conditions.
Initial conditions:
Boundary conditions:
Time complexity: O(1) - returns fixed list

