Skip to content

load-db fails with "Invalid token" when clj-kondo produces TokenNode values for :name in var-definitions #3

@DeLaGuardo

Description

@DeLaGuardo

When analyzing a project that uses certain macros that expands to def, clj-kondo's :var-definitions analysis can produce clj_kondo.impl.rewrite_clj.node.token.TokenNode objects instead of plain symbols for the :name field of some entries.

clj-xref.analyze/transform-var-def copies this value as-is into :local-name

In memory, these TokenNode objects work fine — (str token-node) returns the correct string. But when clj-xref.emit/write-edn serializes the database with prn, the TokenNode's print representation is <token: Foo>, which is not valid EDN. This causes clj-xref.emit/read-edn (and therefore clj-xref.core/load-db) to fail:

Execution error at clj-xref.emit/read-edn (emit.clj:56).
Invalid token: <token:

Looks like the one way to fix it is to coerce :local-name to a symbol in transform-var-def:

:local-name (:name vd)
;; to:
:local-name (symbol (str (:name vd)))

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions