Skip to content

Fix check pattern import#80

Open
vhqr0-hjd wants to merge 1 commit intoflybot-sg:masterfrom
vhqr0-hjd:fix-check-pattern-import
Open

Fix check pattern import#80
vhqr0-hjd wants to merge 1 commit intoflybot-sg:masterfrom
vhqr0-hjd:fix-check-pattern-import

Conversation

@vhqr0-hjd
Copy link

问题:

Problem:

有一个项目同时使用 pull 和 aleph。当我尝试将 aleph 升级到最新版时,打包运行项目会出现大量异常,提示找不到 sg.flybot.pullable.schema/check-pattern! 变量。

A project uses both pull and aleph. When I tried upgrading aleph to the latest version, running the packaged project produced a large number of exceptions indicating that the variable sg.flybot.pullable.schema/check-pattern! could not be found.

分析:

Analysis:

分析更新前后的打包结果,发现 sg.flybot.pullable/query 对应的 class 文件有变化:更新后的 class 文件中出现了 sg.flybot.pullable.schema/check-pattern! 文本,而更新前没有。

After comparing the packaged results before and after the upgrade, I found that the sg.flybot.pullable/query class file had changed: in the new version, the class file contains the text sg.flybot.pullable.schema/check-pattern!, whereas the old version does not.

推测是新版本的 aleph 引入的 malli 依赖导致的:在编译期,有副作用的宏函数加载了 sg.flybot.pullable.schema ns,导致宏展开的结果是使用了 sg.flybot.pullable.schema/check-pattern! 的分支,而编译期环境中也能找到对应的变量,因此可以把宏展开后的结果编译成 class 文件。但在运行期,没有调用有副作用的宏函数加载 sg.flybot.pullable.schema ns,导致找不到 sg.flybot.pullable.schema/check-pattern!。该问题只能在编译期和运行期分离的情景下才能复现。

I suspect that this is caused by the new version of aleph introducing a dependency on malli: during compilation, a macro function with side effects loads the sg.flybot.pullable.schema namespace. As a result, the macro expansion uses the branch referencing sg.flybot.pullable.schema/check-pattern!, and since the corresponding variable is available in the compile-time environment, the expanded form is successfully compiled into the class file. However, at runtime, the macro with side effects is not invoked, so the sg.flybot.pullable.schema namespace is never loaded, leading to a missing sg.flybot.pullable.schema/check-pattern! variable. This issue only occurs in scenarios where the compile-time and runtime environments are separated.

我更建议在运行期尝试加载并绑定 sg.flybot.pullable.schema/check-pattern!:

I recommend attempting to load and bind sg.flybot.pullable.schema/check-pattern! at runtime instead:

(try
  (require 'sg.flybot.pullable.schema)
  (def check-pattern! (ns-resolve 'sg.flybot.pullable.schema 'check-pattern!))
  (catch Exception e
    (defn check-pattern! [data-schema pattern])))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants