fix: correct error message display and improve agent class loading robustness (fixes #1)#2
Conversation
…bustness - RuntimeEvaluationCallback.errorOccurred(): was passing myErrorOccurred (a Consumer<String> lambda) instead of errorMessage (the actual error string) to the message bundle, causing the error dialog to show a garbled Consumer.toString() rather than the real ClassNotFoundException. - ActionExecutorUtil.EXECUTE_EXPRESSION: add Thread context classloader as a fallback when getSystemClassLoader() cannot find the agent class, and throw a descriptive message if neither loader succeeds (e.g. when debugging remotely without the agent attached). Fixes #1
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fca02a0370
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "try { actionExecutorClass = java.lang.ClassLoader.getSystemClassLoader().loadClass(\"com.runtime.pivot.agent.ActionExecutor\"); } catch (java.lang.ClassNotFoundException rtPivotE) {}\n" + | ||
| "if (actionExecutorClass == null) {\n" + | ||
| " java.lang.ClassLoader rtPivotCtxCl = java.lang.Thread.currentThread().getContextClassLoader();\n" + | ||
| " if (rtPivotCtxCl != null) { actionExecutorClass = rtPivotCtxCl.loadClass(\"com.runtime.pivot.agent.ActionExecutor\"); }\n" + |
There was a problem hiding this comment.
Catch context-loader miss before final agent-not-found error
In ActionExecutorUtil.EXECUTE_EXPRESSION, the fallback branch calls rtPivotCtxCl.loadClass(...) without a try/catch, so when the thread context class loader exists but also cannot find com.runtime.pivot.agent.ActionExecutor, a ClassNotFoundException is thrown immediately and the new explicit guidance ("Please restart the application with the agent attached.") is never reached. This regresses the intended error clarity in common environments where a context class loader is present but does not contain the agent; wrap the context-loader call similarly to the system-loader attempt so the final custom exception path is reliably used.
Useful? React with 👍 / 👎.
问题分析 (Issue #1 - ClassNotFoundException)
经过代码分析,找到了两个导致问题的 bug。
Bug 1(关键):错误弹窗显示的是错误的变量
文件:
RuntimeEvaluationCallback.java第 65 行根因:
myErrorOccurred是Consumer<String>类型的 lambda 回调字段,而errorMessage才是方法参数中的实际错误字符串。消息模板{0}需要一个字符串,传入 Consumer 对象后显示的是其toString()(如null或 lambda 引用地址),导致用户无法看到真实的ClassNotFoundException信息。Bug 2(增强):agent 类加载缺乏回退机制
文件:
ActionExecutorUtil.java原代码只通过
ClassLoader.getSystemClassLoader()查找com.runtime.pivot.agent.ActionExecutor,在以下场景会失败:修复:依次尝试系统类加载器 → 线程上下文类加载器,两者都失败时抛出带有明确提示的异常,告知用户需要重启应用并附加 agent。
变更内容
RuntimeEvaluationCallback.errorOccurred():myErrorOccurred→errorMessageActionExecutorUtil.EXECUTE_EXPRESSION: 添加 Thread 上下文类加载器回退,并在 agent 未找到时输出可读的错误提示测试
ClassNotFoundException发生时,弹窗正确显示实际异常信息Generated by Claude Code