Skip to content

Commit

Permalink
Reintroduce try/except TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer committed Aug 17, 2022
1 parent 973fab5 commit 7f63342
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/basic_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ layout:
content:
- BannerImage:
image: ./example_banner.png
title: My banner image
title: My banner image ÆØÅ ølå
- Webviz created from configuration file.
- Some other text, potentially with strange letters like Åre, Smørbukk Sør.

Expand Down
31 changes: 18 additions & 13 deletions webviz_config/_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import pathlib
import inspect
from typing import Dict, List, Optional, Any
from typing import Dict, List, Optional, Any, Type
import warnings

import yaml
Expand Down Expand Up @@ -103,18 +103,23 @@ def _call_signature(
(config_folder / pathlib.Path(patharg)).resolve()
for patharg in kwargs[arg]
]
if not isinstance(kwargs[arg], expected_type):
raise ParserError(
f"{terminal_colors.RED}{terminal_colors.BOLD}"
f"The value provided for argument `{arg}` "
f"given to `{plugin_name}` is "
f"of type `{type(kwargs[arg]).__name__}`. "
f"Expected type "
f"`{argspec.annotations[arg].__name__}`. "
"Run the command `webviz docs` if you want "
"to see documentation of the plugin."
f"{terminal_colors.END}"
)
try:
if not isinstance(kwargs[arg], expected_type):
raise ParserError(
f"{terminal_colors.RED}{terminal_colors.BOLD}"
f"The value provided for argument `{arg}` "
f"given to `{plugin_name}` is "
f"of type `{type(kwargs[arg]).__name__}`. "
f"Expected type "
f"`{argspec.annotations[arg].__name__}`. "
"Run the command `webviz docs` if you want "
"to see documentation of the plugin."
f"{terminal_colors.END}"
)
# We currently do not support subscriptable types, e.g. Optional[], List[], Dict[] etc.
# This will be supported after https://github.com/equinor/webviz-config/issues/199
except TypeError:
pass

kwargs_including_defaults = kwargs
plugin_deprecation_warnings = []
Expand Down

0 comments on commit 7f63342

Please sign in to comment.