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:
committed by
Copybara-Service
parent
450e7ff777
commit
c5f958bdff
@@ -103,7 +103,7 @@ std::unique_ptr<Pid> Pid::Create(const mjModel* m, int instance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.slew_max.value_or(0.0) < 0) {
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3257,7 +3257,14 @@ mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m) {
|
|||||||
try {
|
try {
|
||||||
if (setjmp(error_jmp_buf) != 0) {
|
if (setjmp(error_jmp_buf) != 0) {
|
||||||
// TryCompile resulted in an mju_error which was converted to a longjmp.
|
// 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);
|
TryCompile(*const_cast<mjModel**>(&model), *const_cast<mjData**>(&data), vfs);
|
||||||
} catch (mjCError err) {
|
} catch (mjCError err) {
|
||||||
|
|||||||
@@ -648,8 +648,8 @@ TEST_F(PidTest, InvalidClamp) {
|
|||||||
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
|
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
|
||||||
EXPECT_THAT(m, IsNull());
|
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("plugin"));
|
||||||
|
EXPECT_THAT(std::string_view(error), HasSubstr("imax"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PidTest, InvalidSlew) {
|
TEST_F(PidTest, InvalidSlew) {
|
||||||
@@ -679,8 +679,8 @@ TEST_F(PidTest, InvalidSlew) {
|
|||||||
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
|
mjModel* m = LoadModelFromString(kModelXml, error, sizeof(error));
|
||||||
ASSERT_THAT(m, IsNull());
|
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("plugin"));
|
||||||
|
EXPECT_THAT(std::string_view(error), HasSubstr("slewmax"));
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
|
|||||||
Reference in New Issue
Block a user