From 55d7226b06db5c2c025ad8ecc724741145e4f101 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Thu, 26 Feb 2026 06:58:06 -0800 Subject: [PATCH] Improve error handling of spec editor compilation. PiperOrigin-RevId: 875703124 Change-Id: Idf4a90a48d75185ad03e4469cee9098104751d67 --- src/experimental/platform/model_holder.cc | 2 +- src/experimental/studio/app.cc | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/experimental/platform/model_holder.cc b/src/experimental/platform/model_holder.cc index c62bfd83..a59105be 100644 --- a/src/experimental/platform/model_holder.cc +++ b/src/experimental/platform/model_holder.cc @@ -78,7 +78,7 @@ void ModelHolder::PostInit() { if (spec_ && !model_) { model_ = mj_compile(spec_, &vfs_); if (!model_) { - SetLoadError("Error compiling model from spec."); + SetLoadError(mjs_getError(spec_)); return; } } diff --git a/src/experimental/studio/app.cc b/src/experimental/studio/app.cc index 66d71d34..12bce034 100644 --- a/src/experimental/studio/app.cc +++ b/src/experimental/studio/app.cc @@ -1287,9 +1287,15 @@ void App::SpecEditorGui() { ImGui::PushStyleColor(ImGuiCol_Button, ImColor(40, 180, 40, 255).Value); if (ImGui::Button("Compile and Reload", ImVec2(-1, 0))) { spec_op_ = [this]() { - model_holder_ = platform::ModelHolder::FromSpec(scratch_spec_); - scratch_spec_ = nullptr; - OnModelLoaded(model_name_, model_kind_); + auto tmp_holder = platform::ModelHolder::FromSpec(scratch_spec_); + if (tmp_holder->ok()) { + model_holder_ = std::move(tmp_holder); + scratch_spec_ = nullptr; + OnModelLoaded(model_name_, model_kind_); + } else { + scratch_spec_ = tmp_holder->ReleaseSpec(); + load_error_ = std::move(tmp_holder->error()); + } }; } ImGui::PopStyleColor();