Skip to content

Commit

Permalink
feat core: improve diagnostic messages for component system
Browse files Browse the repository at this point in the history
Tests: протестировано CI
commit_hash:503721d2817b9a4745b241513a87d50f8a6f2d6e
  • Loading branch information
apolukhin committed Oct 30, 2024
1 parent 9c97751 commit 285201a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
19 changes: 10 additions & 9 deletions core/src/components/component_context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ ComponentContextImpl::TaskToComponentMapScope::TaskToComponentMapScope(
if (!res.second)
throw std::runtime_error(
"can't create multiple components in the same task simultaneously: "
"component " +
std::string{res.first->second.StringViewName()} + " is already registered for current task"
"component '" +
std::string{res.first->second.StringViewName()} + "' is already registered for current task"
);
}

Expand Down Expand Up @@ -328,8 +328,9 @@ void ComponentContextImpl::ProcessSingleComponentLifetimeStageSwitching(
auto& dependency_to = (params.dependency_type == DependencyType::kInverted ? name : component_name);
auto& other_component_info = components_.at(component_name);
if (other_component_info.GetStage() != params.next_stage) {
LOG_DEBUG() << "Cannot call " << params.stage_switch_handler_name << " for component " << name << " yet ("
<< dependency_from << " depends on " << dependency_to << ")";
LOG_DEBUG() << "Cannot call " << params.stage_switch_handler_name << " for component '" << name << "' yet. "
<< "Component '" << dependency_from << "' is waiting for '" << dependency_to
<< "' component to complete its " << params.stage_switch_handler_name << " call.";
other_component_info.WaitStage(params.next_stage, params.stage_switch_handler_name);
}
};
Expand All @@ -339,14 +340,14 @@ void ComponentContextImpl::ProcessSingleComponentLifetimeStageSwitching(
else
component_info.ForEachDependsOnIt(wait_cb);

LOG_DEBUG() << "Call " << params.stage_switch_handler_name << " for component " << name;
LOG_DEBUG() << "Call " << params.stage_switch_handler_name << " for component '" << name << "'";
(component_info.*params.stage_switch_handler)();
} catch (const impl::StageSwitchingCancelledException& ex) {
LOG_WARNING() << params.stage_switch_handler_name << " failed for component " << name << ": " << ex;
LOG_WARNING() << params.stage_switch_handler_name << " failed for component '" << name << "': " << ex;
component_info.SetStage(params.next_stage);
throw;
} catch (const std::exception& ex) {
LOG_ERROR() << params.stage_switch_handler_name << " failed for component " << name << ": " << ex;
LOG_ERROR() << params.stage_switch_handler_name << " failed for component '" << name << "': " << ex;
if (params.allow_cancelling) {
component_info.SetStageSwitchingCancelled(true);
if (!params.is_component_lifetime_stage_switchings_cancelled.exchange(true)) {
Expand Down Expand Up @@ -410,8 +411,8 @@ RawComponentBase* ComponentContextImpl::DoFindComponent(std::string_view name) {
engine::TaskCancellationBlocker block_cancel;
auto data = shared_data_.Lock();
this_component_name = GetLoadingComponentName(*data);
LOG_DEBUG() << "component " << name << " is not loaded yet, component " << this_component_name
<< " is waiting for it to load";
LOG_DEBUG() << "Component '" << name << "' is not loaded yet, component '" << this_component_name
<< "' is waiting for it to load";
}
SearchingComponentScope finder(*this, this_component_name);

Expand Down
22 changes: 7 additions & 15 deletions core/src/engine/task/task_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,21 @@ bool TaskBase::IsValid() const { return !!pimpl_->context; }
Task::State TaskBase::GetState() const { return pimpl_->context ? pimpl_->context->GetState() : State::kInvalid; }

std::string_view TaskBase::GetStateName(State state) {
static const std::string kInvalid = "kInvalid";
static const std::string kNew = "kNew";
static const std::string kQueued = "kQueued";
static const std::string kRunning = "kRunning";
static const std::string kSuspended = "kSuspended";
static const std::string kCancelled = "kCancelled";
static const std::string kCompleted = "kCompleted";

switch (state) {
case State::kInvalid:
return kInvalid;
return "kInvalid";
case State::kNew:
return kNew;
return "kNew";
case State::kQueued:
return kQueued;
return "kQueued";
case State::kRunning:
return kRunning;
return "kRunning";
case State::kSuspended:
return kSuspended;
return "kSuspended";
case State::kCancelled:
return kCancelled;
return "kCancelled";
case State::kCompleted:
return kCompleted;
return "kCompleted";
}

UINVARIANT(false, "Unexpected Task state");
Expand Down

0 comments on commit 285201a

Please sign in to comment.