[jrubyscripting] log Ruby stacktrace on exception from JRuby (#13778)

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer 2022-11-26 00:19:22 -07:00 committed by GitHub
parent ea134d8215
commit 4739f126a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,7 +199,7 @@ public class JRubyScriptEngineConfiguration {
logger.trace("Gem install code:\n{}", gemCommand);
engine.eval(gemCommand);
} catch (ScriptException e) {
logger.warn("Error installing Gems: {}", e.getMessage());
logger.warn("Error installing Gems", unwrap(e));
}
}
@ -221,7 +221,7 @@ public class JRubyScriptEngineConfiguration {
logger.trace("Injecting require statement: {}", requireStatement);
engine.eval(requireStatement);
} catch (ScriptException e) {
logger.warn("Error evaluating statement {}: {}", requireStatement, e.getMessage());
logger.warn("Error evaluating `{}`", requireStatement, unwrap(e));
}
});
}
@ -239,7 +239,7 @@ public class JRubyScriptEngineConfiguration {
logger.trace("Setting Ruby environment with code: {} ", environmentSetting);
engine.eval(environmentSetting);
} catch (ScriptException e) {
logger.warn("Error setting ruby environment", e);
logger.warn("Error setting Ruby environment", unwrap(e));
}
});
@ -267,7 +267,7 @@ public class JRubyScriptEngineConfiguration {
try {
engine.eval(code);
} catch (ScriptException exception) {
logger.warn("Error setting $LOAD_PATH from RUBYLIB='{}': {}", rubyLib.get(), exception.getMessage());
logger.warn("Error setting $LOAD_PATH from RUBYLIB='{}'", rubyLib.get(), unwrap(exception));
}
}
}
@ -293,6 +293,20 @@ public class JRubyScriptEngineConfiguration {
.filter(element -> element.getValue().isPresent());
}
/**
* Unwraps the cause of an exception, if it has one.
*
* Since a user cares about the _Ruby_ stack trace of the throwable, not
* the details of where openHAB called it.
*/
private Throwable unwrap(Throwable e) {
Throwable cause = e.getCause();
if (cause != null) {
return cause;
}
return e;
}
/**
* Inner static companion class for configuration elements
*/