mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-18 09:53:40 -05:00
fix: add custom exceptions (#29)
* feat: add custom exceptions to metadata creation * refactor: utility function for finding inline metadata in content * fix: use InlineTagError for exceptions parsing inline tags * fix: improve error messages * build(deps): bump dependencies * fix: use BadParameter exception when appropriate
This commit is contained in:
@@ -10,6 +10,7 @@ from obsidian_metadata._utils.utilities import (
|
||||
dict_keys_to_lower,
|
||||
dict_values_to_lists_strings,
|
||||
docstring_parameter,
|
||||
inline_metadata_from_string,
|
||||
merge_dictionaries,
|
||||
remove_markdown_sections,
|
||||
rename_in_dict,
|
||||
@@ -27,6 +28,7 @@ __all__ = [
|
||||
"dict_values_to_lists_strings",
|
||||
"docstring_parameter",
|
||||
"LoggerManager",
|
||||
"inline_metadata_from_string",
|
||||
"merge_dictionaries",
|
||||
"rename_in_dict",
|
||||
"remove_markdown_sections",
|
||||
|
||||
@@ -178,8 +178,7 @@ class LoggerManager:
|
||||
self.log_level = log_level
|
||||
|
||||
if self.log_file == Path("/logs") and self.log_to_file: # pragma: no cover
|
||||
console.print("No log file specified")
|
||||
raise typer.Exit(1)
|
||||
raise typer.BadParameter("No log file specified")
|
||||
|
||||
if self.verbosity >= VerboseLevel.TRACE.value:
|
||||
logger.remove()
|
||||
|
||||
@@ -183,6 +183,21 @@ def docstring_parameter(*sub: Any) -> Any:
|
||||
return dec
|
||||
|
||||
|
||||
def inline_metadata_from_string(string: str) -> list[tuple[Any, ...]]:
|
||||
"""Search for inline metadata in a string and return a list tuples containing (key, value).
|
||||
|
||||
Args:
|
||||
string (str): String to get metadata from
|
||||
|
||||
Returns:
|
||||
tuple[str]: (key, value)
|
||||
"""
|
||||
from obsidian_metadata.models import Patterns
|
||||
|
||||
results = Patterns().find_inline_metadata.findall(string)
|
||||
return [tuple(filter(None, x)) for x in results]
|
||||
|
||||
|
||||
def merge_dictionaries(dict1: dict, dict2: dict) -> dict:
|
||||
"""Merge two dictionaries. When the values are lists, they are merged and sorted.
|
||||
|
||||
@@ -322,4 +337,4 @@ def version_callback(value: bool) -> None:
|
||||
"""Print version and exit."""
|
||||
if value:
|
||||
console.print(f"{__package__.split('.')[0]}: v{__version__}")
|
||||
raise typer.Exit()
|
||||
raise typer.Exit(0)
|
||||
|
||||
Reference in New Issue
Block a user