From c80dc9bdf3dd27f2e7c756c3d6b2afcc3d1edac2 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 13 Oct 2025 16:39:17 +0200 Subject: [PATCH] converting char array+int in runtimeerror compiles but throws at runtime.Fixed.Tested for it. Also check if string or int before using getregisterdefinitonbyvalue to see if it threw to call the other function. because both of it can throw and we should differentiate the issues for both --- slsDetectorSoftware/src/CallerSpecial.cpp | 13 ++++++++++--- slsDetectorSoftware/src/DetectorImpl.cpp | 2 +- .../tests/Caller/test-Caller-chiptestboard.cpp | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index 43a7fe196..28fd0f544 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -1480,13 +1480,20 @@ std::string Caller::define(int action) { WrongNumberOfParameters(2); } if (mode == "reg") { + bool value_found = false; try { - // get name from address + StringTo(args[1]); + value_found = true; + } catch (...) { + } + // get name from address + if (value_found) { int addr = StringTo(args[1]); auto t = det->getRegisterDefinitionByValue(addr); os << t << '\n'; - } catch (...) { - // get address from name + } + // get address from name + else { auto t = det->getRegisterDefinitionByName(args[1]); os << ToStringHex(t) << '\n'; } diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 4955103ea..128b5abba 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -2092,7 +2092,7 @@ std::string DetectorImpl::getRegisterDefinitionByValue(const int value) const { auto val = ctb_shm()->getRegisterName(value); if (!val.has_value()) { throw RuntimeError("No register definition found for address: " + - value); + ToStringHex(value)); } return val.value(); } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp index 5448f736c..e33ff7331 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-chiptestboard.cpp @@ -1409,8 +1409,21 @@ TEST_CASE("define", "[.cmdcall]") { REQUIRE_NOTHROW( caller.call("define", {"bit", "MICRO_BIT", "4"}, -1, PUT)); std::ostringstream oss, oss1; - caller.call("define", {"reg", "REG_MACRO"}, -1, GET, oss); - caller.call("define", {"bit", "MACRO_BIT"}, -1, GET, oss1); + REQUIRE_NOTHROW( + caller.call("define", {"reg", "REG_MACRO"}, -1, GET, oss)); + REQUIRE_NOTHROW( + caller.call("define", {"bit", "MACRO_BIT"}, -1, GET, oss1)); + + REQUIRE_NOTHROW(caller.call("define", {"reg", "0x202"}, -1, GET)); + REQUIRE_THROWS(caller.call("define", {"reg", "0x203"}, -1, GET)); + + try { + caller.call("define", {"reg", "0x203"}, -1, GET, oss); + } catch (const std::exception &e) { + REQUIRE(std::string(e.what()) == + "No register definition found for address: 0x203"); + } + REQUIRE(oss.str() == "define 0x202\n"); REQUIRE(oss1.str() == "define 2\n"); }