Fork me on GitHub
#unrepl
<
2018-01-25
>
ghadi14:01:49

How can I make a little snippet for SPIRAL that does a require/load rather than eval current buffer? (eval current buffer loses line info)

volrath14:01:20

@ghadi not sure I understand the question

cgrand14:01:16

blind guess: spiral is not setting file/line info before eval

ghadi14:01:30

hey @volrath. I'm really enjoying SPIRAL. Is spiral-eval-buffer calling (require 'foo) or (load "foo") or is it feeding the contents of the buffer to the REPL?

volrath14:01:24

spiral-eval-buffer uses clojure.lang.Compiler/load

volrath14:01:53

it sends the whole file content, the file name and path to that function

ghadi14:01:27

I see. Yeah if I call it, and then the code later throws an exception, the line/file info is missing/wrong

ghadi14:01:10

sorry, words: if I eval-buffer, then my code throws an exception, line/file info is lost

ghadi14:01:15

Need more caffeine.

volrath14:01:28

haha, let me try to reproduce

volrath14:01:14

hmm, I tried this:

volrath14:01:21

(ns spiral.connect)

(/ 1 0)

volrath14:01:30

spiral-eval-buffer on that raises:

volrath14:01:56

Unhandled Exception
            java.lang.ArithmeticException: Divide by zero
  clojure.lang.Compiler$CompilerException: java.lang.ArithmeticException: Divide by zero, compiling:(connect.clj:3:1)

                                                            Numbers.java:  163 - clojure.lang.Numbers/divide
                                                            Numbers.java: 3833 - clojure.lang.Numbers/divide
  /home/volrath/projects/tests/spiral-tests/src/spiral_tests/connect.clj:    3 - spiral.connect$eval1304/invokeStatic
  /home/volrath/projects/tests/spiral-tests/src/spiral_tests/connect.clj:    3 - spiral.connect$eval1304/invoke
                                                           Compiler.java: 7062 - clojure.lang.Compiler/eval
                                                           Compiler.java: 7514 - clojure.lang.Compiler/load
                                                           load_file.clj:    9 - spiral.tools.load_file$load_file_code/invokeStatic
                                                           load_file.clj:    4 - spiral.tools.load_file$load_file_code/invoke
                                                          unrepl-session:    7 - user$eval1292/invokeStatic
                                                          unrepl-session:    7 - user$eval1292/invoke
 ...

volrath14:01:17

seems to be correct, I think

ghadi14:01:43

Let me try to reproduce your reproduction

ghadi14:01:31

yeah, seems correct. Thanks for the sanity check

volrath14:01:12

alright cool, let me know either way if you find the solution to your problem... you could also try to load the file in a regular repl, just to discard unrepl/spiral completely

ghadi14:01:24

@cgrand ever done authentication in socket server during repl :init?

ghadi14:01:17

I had a socket server exposed to the internet:

(defn check-auth
  [secret]
  (when-not (= secret (edn/read))
    (println "go away")
    (throw (Exception. "Unauthenticated"))))

(defn repl
  []
  (check-auth :MAGICVALUE)
  (clojure.main/repl
    :init #(in-ns 'user)
    :read clojure.core.server/repl-read))

ghadi15:01:55

could do that, but I have it in a remote docker container, was trying to avoid a sidecar process

cgrand15:01:40

but if you really really want to you could use a special accept fn and add your secret at the start of the blob (BYOB ftw)

cgrand15:01:03

I strongly discourage pursuing such an endeavor 🙂

gcast16:01:08

(require '[net.cgrand.xforms :as x]
                               '[clojure.string :as str]
                               '[jsonista.core :as j]
                               '[clojure.pprint :refer [pprint] :rename {pprint p*}]
                               '[ :as io] :reload-all)
~ Unhandled Exception
       java.lang.IllegalArgumentException: argument type mismatch
  clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: argument type mismatch, compiling:(jsonista/core.clj:1:1)

      NativeMethodAccessorImpl.java:  -2 - sun.reflect.NativeMethodAccessorImpl/invoke0
      NativeMethodAccessorImpl.java:  62 - sun.reflect.NativeMethodAccessorImpl/invoke
  DelegatingMethodAccessorImpl.java:  43 - sun.reflect.DelegatingMethodAccessorImpl/invoke
                        Method.java: 497 - java.lang.reflect.Method/invoke
                     NO_SOURCE_FILE: 397 - unrepl.replG__1676$classloader$fn__1932/invoke
                                nil:  -1 - unrepl.replG__1676.proxy$java.lang.ClassLoader$ff19274a/findClass
                   ClassLoader.java: 424 - java.lang.ClassLoader/loadClass
                                nil:  -1 - unrepl.replG__1676.proxy$java.lang.ClassLoader$ff19274a/loadClass
                   ClassLoader.java: 411 - java.lang.ClassLoader/loadClass
            DynamicClassLoader.java:  77 - clojure.lang.DynamicClassLoader/loadClass

gcast16:01:15

might this be unrepl or spiral?

cgrand16:01:12

unrepl but should be fixed; running latest spiral?

cgrand16:01:15

Right now it’s a placeholder but of someone wants to step in, I can provide a master plan

gcast16:01:50

@cgrand latest spiral as of two days ago

gcast16:01:02

currently I use spiral over ssh tunnels

gcast16:01:12

tunnels built at command line

cgrand17:01:53

What's melpa latency?

volrath17:01:38

it used to be really quick (a minute or so) but a few weeks ago I noticed it would take a couple of hours to update. I don't know if it was a circumstantial anomaly or that's the way it is now

volrath17:01:02

you can check out here: https://melpa.org/#/spiral when version changes to 20180125.XXXX, the latest changes are up

volrath17:01:17

although a most reliable way would be to check within emacs, cause maybe the latency is in their website. tbh, I don't know

mhcat20:01:54

Melpa advertises its build time fwiw - right now it says "Current build started: an hour ago, last took 3 hours"