diff --git a/src/common/generators/plantuml/generator.h b/src/common/generators/plantuml/generator.h index 9749b7df..f9b660b9 100644 --- a/src/common/generators/plantuml/generator.h +++ b/src/common/generators/plantuml/generator.h @@ -273,6 +273,11 @@ void generator::generate_plantuml_directives( ostr << directive << '\n'; } + catch (const clanguml::error::uml_alias_missing &e) { + LOG_ERROR("Failed to render PlantUML directive due to unresolvable " + "alias: {}", + e.what()); + } catch (const inja::json::parse_error &e) { LOG_ERROR("Failed to parse Jinja template: {}", d); } @@ -547,6 +552,10 @@ template void generator::init_env() auto element_opt = m_model.get_with_namespace( args[0]->get(), m_config.using_namespace()); + if (!element_opt.has_value()) + throw clanguml::error::uml_alias_missing( + args[0]->get()); + return element_opt.value().alias(); }); @@ -557,16 +566,18 @@ template void generator::init_env() // m_env.add_callback("comment", 1, [this](inja::Arguments &args) { inja::json res{}; - auto element = m_model.get_with_namespace( + auto element_opt = m_model.get_with_namespace( args[0]->get(), m_config.using_namespace()); - if (element.has_value()) { - auto comment = element.value().comment(); + if (!element_opt.has_value()) + throw clanguml::error::uml_alias_missing( + args[0]->get()); - if (comment.has_value()) { - assert(comment.value().is_object()); - res = comment.value(); - } + auto comment = element_opt.value().comment(); + + if (comment.has_value()) { + assert(comment.value().is_object()); + res = comment.value(); } return res; diff --git a/tests/t00050/.clang-uml b/tests/t00050/.clang-uml index eb7a1326..bf7ef914 100644 --- a/tests/t00050/.clang-uml +++ b/tests/t00050/.clang-uml @@ -13,9 +13,13 @@ diagrams: plantuml: after: - > - note left of {{ alias("A") }} - {{ comment("clanguml::t00050::A").formatted }} - end note + note left of {{ alias("NoSuchClass") }} + {{ comment("NoSuchClass").formatted }} + end note + - > + note left of {{ alias("A") }} + {{ comment("clanguml::t00050::A").formatted }} + end note - > note right of {{ element("clanguml::t00050::A").alias }} {% set e=element("clanguml::t00050::A") %} {{ e.comment.formatted }}