vim-fireplace icon indicating copy to clipboard operation
vim-fireplace copied to clipboard

How to read env variables with fireplace

Open himat opened this issue 3 years ago • 0 comments

I have this in a function in my clj file

  (def access-token (env :api-access-token))

When I try to use fireplace to run a function that calls that line, I get this error in the fireplace vim pane

Execution error (ClassCastException) at ....
class mount.core.DerefableState cannot be cast to class clojure.lang.IFn (mount.core.DerefableState is in unnamed module
 of loader clojure.lang.DynamicClassLoader @5d235104; clojure.lang.IFn is in unnamed module of loader 'app')
Clojure: class java.lang.ClassCastException

I assume this is because fireplace hasn't (can't?) load the env file.

Here's the env definition. It just reads a value defined in my dev-config.edn file.

(ns super-browser-tool.config
  (:require
    [cprop.core :refer [load-config]]
    [cprop.source :as source]
    [mount.core :refer [args defstate]]))

(defstate env
  :start
  (load-config
    :merge
    [(args)
     (source/from-system-props)
     (source/from-env)]))

How do people normally deal with this? I can temporarily hardcode the value in the code as (def access-token "some string") but that's messy and I have to remember to undo that when I commit my code.

himat avatar Aug 09 '22 04:08 himat