Skip to content

Commit

Permalink
Update error message and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirAE committed Feb 27, 2024
1 parent fce1bb3 commit 1eba589
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/sections/user_guide/cli/tools/mode_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,16 @@ and an additional supplemental YAML file ``values2.yaml`` with the following con
.. note:: In recognition of the different sets of value types representable in each config format, ``uw`` supports two format-combination schemes:

1. **Output matches input:** The format of the output config matches that of the input config.
2. **Input is YAML:** If the input config is YAML, any output format may be requested. In the worst case, values always have a string representation, but note that, for example, the string representation of a YAML sequence (Python ``list``) in an INI output config may not be useful.
2. **YAML:** YAML is accepted as either input or output with any other format. In the worst case, values always have a string representation, but note that, for example, the string representation of a YAML sequence (Python ``list``) in an INI output config may not be useful.

In all cases, any supplemental configs must be in the same format as the input config and must have recognized extensions.

``uw`` considers invalid combination requests errors:

.. code-block:: text
$ uw config realize --input-file b.nml --output-file a.yaml
Output format yaml must match input format nml
$ uw config realize --input-file b.nml --output-file a.ini
Accepted output formats for input format nml are nml or yaml
.. code-block:: text
Expand Down
3 changes: 1 addition & 2 deletions src/uwtools/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ def _validate_format_output(input_fmt: str, output_fmt: str) -> None:
"""
if FORMAT.yaml not in (input_fmt, output_fmt) and input_fmt != output_fmt:
raise UWError(
"Output format %s must match input format %s unless either is YAML"
% (output_fmt, input_fmt)
"Accepted output formats for input format %s are %s or yaml" % (input_fmt, input_fmt)
)


Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/config/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ def test__validate_format_output(input_fmt, output_fmt):
with raises(UWError) as e:
call()
assert (
str(e.value) == f"Output format {output_fmt} must match input format {input_fmt}"
" unless either is YAML"
str(e.value) == "Accepted output formats for input format "
f"{input_fmt} are {input_fmt} or yaml"
)


Expand Down

0 comments on commit 1eba589

Please sign in to comment.