When reporting compilation errors, include warning strings.

This allows plugins to call mju_warning, and have the string propagate to users.

PiperOrigin-RevId: 650621601
Change-Id: I608e7a3a1ad126ab8da2ff0634fa708458fb9ccc
This commit is contained in:
Nimrod Gileadi
2024-07-09 07:32:26 -07:00
committed by Copybara-Service
parent 450e7ff777
commit c5f958bdff
3 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ std::unique_ptr<Pid> Pid::Create(const mjModel* m, int instance) {
}
if (config.slew_max.value_or(0.0) < 0) {
mju_warning("maxslew must be non-negative");
mju_warning("slewmax must be non-negative");
return nullptr;
}
+8 -1
View File
@@ -3257,7 +3257,14 @@ mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m) {
try {
if (setjmp(error_jmp_buf) != 0) {
// TryCompile resulted in an mju_error which was converted to a longjmp.
throw mjCError(0, "engine error: %s", errortext);
std::string error_msg = errortext;
// also include the last warning that was issued. this is useful for
// warnings that came out of plugin implementations.
if (warningtext[0]) {
error_msg += "\n";
error_msg += warningtext;
}
throw mjCError(0, "engine error: %s", error_msg.c_str());
}
TryCompile(*const_cast<mjModel**>(&model), *const_cast<mjData**>(&data), vfs);
} catch (mjCError err) {
+2 -2
View File
@@ -648,8 +648,8 @@ TEST_F(PidTest, InvalidClamp) {
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
EXPECT_THAT(m, IsNull());
// TODO: b/303654852 - ensure that the compilation error includes "imax"
EXPECT_THAT(std::string_view(error), HasSubstr("plugin"));
EXPECT_THAT(std::string_view(error), HasSubstr("imax"));
}
TEST_F(PidTest, InvalidSlew) {
@@ -679,8 +679,8 @@ TEST_F(PidTest, InvalidSlew) {
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
ASSERT_THAT(m, IsNull());
// TODO: b/303654852 - ensure that the compilation error includes "slewmax"
EXPECT_THAT(std::string_view(error), HasSubstr("plugin"));
EXPECT_THAT(std::string_view(error), HasSubstr("slewmax"));
}
} // namespace
} // namespace mujoco