Fork me on GitHub
#clojure
<
2017-07-02
>
jgeraert05:07:26

@petr Sounds like an ipv6 issue. What OS are you running on, try adding -Djava.net.preferIPv4Stack=true to your JAVA_OPTS

mbertheau08:07:07

Is there an obvious way to write the following without repeating x? (if (some-pred? x) y x)

mbertheau08:07:19

Meaning if x is ok, just use it, otherwise use the alternative y

Aleh Atsman08:07:02

Hi, guys when i am tring to deploy library to clojurejars i get “gpg: signing failed: Inappropriate ioctl for device “. I generated key, published it and i added it’s id to ~/.lein/profiles.clj What can be a root of problem?

Aleh Atsman09:07:52

The solution is to add this line to .bash_profile export GPG_TTY=$(tty)

val_waeselynck09:07:53

@mbertheau maybe look at cond-> ?

mbertheau09:07:36

@val_waeselynck You'd have to repeat x just the same

triss11:07:12

hey all. I’m use data.zip.xml/xml-> to parse some XML

triss11:07:56

deep breath… ok:

triss11:07:23

I’m trying to navigate a blob of XML and parse out a map of information

triss11:07:33

this gives me a list of the names of all the interesting nodes in my XML:

(xml-> zipped :parameters :parameter (attr :name))

triss11:07:13

this works for me since I know how many :parameter nodes I have and I know they all have :name

triss11:07:51

these work similarily:

(xml-> zipped :parameters :parameter :description text)
(xml-> zipped :parameters :parameter :default text)
(xml-> zipped :parameters :parameter :options :option text)

triss11:07:05

I get a list of descriptions, default values or options… however! not all my paramater nodes have a :`description`, :default or :options sub tag. So the lists don’t have the same ordering as the :name attr we pulled out earlier…

triss11:07:59

Is there a simple way to pull out these values for each parameter? with say nil returned if it’s not present?

weavejester14:07:20

@triss Perhaps something like:

(for [p (xml-> (z/xml-zip xml) :parameters :parameter), :let [z (z/xml-zip p)]]
  {:description (xml-> z :description text)
   :default     (xml-> z :default text)
   :options     (xml-> z :options :option text)})

weavejester14:07:43

Or alternatively:

(defn parse-parameter [z]
  [{:description (xml-> z :description text)
    :default     (xml-> z :default text)
    :options     (xml-> z :options :option text)}])

(xml-> zipped :parameters :parameter parse-parameter)

PB17:07:59

@jgeraert It’s actually a docker container I use for my dev environment. I have set that environment variable to no avail. Have you had this issue?

jgeraert07:07:05

petr: I'm not sure about docker, i only recall that that specific exception was related to ipv6 on a non-clojure project.

noisesmith17:07:11

@petr is it something that happens to leiningen regardless of the project code? is it a specific network operation in the code that is getting that error?

PB18:07:27

@noisesmith It seems to only happen when running on my docker-container. The repl is being started with this function:

(defn start-repl-server []
  (loop [port (get-repl-server-port)]
    (if-let [server  (try (nrepl-server/start-server :port port
                                                     :handler cider-nrepl/cider-nrepl-handler)
                          (catch java.net.BindException _ nil))]
      (reset! repl-server server)
        (recur (inc port)))))

PB18:07:51

If I start it using lein repl it starts fine just fine (please excuse the indentation, slack appears to have messed it up)

noisesmith18:07:18

what I'm asking is that if it's only with your project in the container that lein gets the error, or if other projects give a similar error

noisesmith18:07:39

there's two likely failure points here, one internal to leiningen, the other specific to your project...

noisesmith18:07:08

another thing you could test is whether an uberjar of your project, run without leiningen gets this error

PB18:07:31

@noisesmith it is the only project I’ve experienced with this error. But I don’t usually do things this way. (with starting the repl in that way)

PB18:07:36

That’s a good idea

PB18:07:38

I’ll try that now

noisesmith18:07:04

do you need to whitelist the ports your process in the container can use?

PB18:07:12

@noisesmith I do, and I have whitelisted those ports

PB18:07:17

The uberjar didn’t work either

PB18:07:49

As that repl function is still unable to run to whatever ip restrictions

noisesmith18:07:24

how does (get-repl-server-port) pick a port?

noisesmith18:07:17

it might be worth trying to just listen to the port it should be listening on using nc

noisesmith18:07:07

eg nc -l 8888 should listen on port 8888 and wait for one connection and print whatever gets sent to it

PB18:07:23

That’s another good idea

PB18:07:56

It picks it from an environment variable:

(defn- get-repl-server-port []
  (let [repl-port-string (get env :repl-server-port "7888")
        maybeNumber (clojure.edn/read-string repl-port-string)]
    (if (number? maybeNumber)
      maybeNumber
      (do
        (log/warn "Unable to parse port number for REPL_SERVER_PORT")
        nil))))

PB18:07:37

Let’s move this to a thread, if you don’t mind? @noisesmith

PB18:07:03

I’m unable to start the server while listening to that port. The address is already in use

noisesmith18:07:13

what I meant was to test if you could open the port with nc - that rules out another point of failure

PB18:07:47

Oh yes, the port is definitely open. The api serves traffic. The nrepl server just won’t start

noisesmith18:07:45

I'm talking about the nrepl port not the api port, but OK

PB18:07:55

Ah, let’s make sure of that

PB18:07:30

Yep, the nrepl port is definitely available as well

noisesmith18:07:05

OK - that verifies it's an nrepl problem then?

PB18:07:14

That’s my guess

PB18:07:36

But nrepl works fine when I start the server using lein repl

noisesmith18:07:41

is it trying to bind to localhost?

noisesmith18:07:53

you could double check eg. that localhost is resolved in the vm

noisesmith18:07:03

sometimes you need to add that mapping by hand

noisesmith18:07:17

and localhost not being found would be consistent with that error

PB18:07:33

So that might actually be it, when I start the nrepl server using lein repl, I also add lein repl :headless :host 0.0.0.0 :port 4343

noisesmith18:07:31

you could try adding :host to the args map to start-server

PB18:07:56

That’s a good idea

PB18:07:58

I’ll try it now

PB18:07:50

Different error, not sure if it’s failing sooner: Exception in thread "main" java.lang.NumberFormatException: Invalid number: 0.0.0.0

PB18:07:54

The host is looking for a number?

noisesmith18:07:31

wait, are you providing 0.0.0.0 or "0.0.0.0" because clojure will give that error for the first one

noisesmith18:07:45

0.0.0.0 is an invalid literal in clojure, is what that means

PB18:07:28

If you look st 0.2.8

noisesmith18:07:51

right - just make sure :host is a String

noisesmith18:07:12

I bet that will work

PB18:07:48

That did it

noisesmith18:07:11

np - glad I could help

noisesmith19:07:10

btw it might be better for security to adjust /etc/hosts so that localhost is defined, rather than providing 0.0.0.0 as your host - I'm not an expert on these things though

noisesmith19:07:10

IIRC 127.0.0.1 can be used instead of 0.0.0.0 and is safer (but if you intend to connect from outside the vm... maybe you need the 0.0.0.0 binding)

PB19:07:12

You’re right. If this were to be deployed with an nrepl server started it would certainly be a security concern

noisesmith19:07:52

anyway, at least you know the precise parameters now and can make an informed decision

PB19:07:05

Indeed, I very much appreciate the help

noisesmith19:07:45

I seem to recall a recommendation to bind on 127.0.0.1 inside the vm, and use an ssh tunnel to access it from the host

noisesmith19:07:52

but maybe that's silly.

PB19:07:44

I’ll test to see if 127.0.0.1 works as well

schmee20:07:07

@mpenet hello! I’m trying out https://github.com/mpenet/spandex, and I’m getting this error when take!-ing from a scroll-chan:

#error {
 :cause Response Exception
 :data #qbits.spandex.Response{:body {:error {:root_cause [{:type illegal_argument_exception, :reason Failed to parse request body}], :type illegal_argument_exception, :reason Failed to parse request body, :caused_by {:type json_parse_exception, :reason Unrecognized token 'DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAAEKFlFLeXR6MDh2UTRxLVdkLVhEbXZSMFEAAAAAAAABCxZRS3l0ejA4dlE0cS1XZC1YRG12UjBRAAAAAAAAAQ0WUUt5dHowOHZRNHEtV2QtWERtdlIwUQAAAAAAAAEMFlFLeXR6MDh2UTRxLVdkLVhEbXZSMFEAAAAAAAABDhZRS3l0ejA4dlE0cS1XZC1YRG12UjBR': was expecting ('true', 'false' or 'null')

schmee20:07:23

any idea what might be going on here?

mpenet20:07:11

If you give me the detail of the request I can have a look. Worse case tomorrow. We can do that in priv msg btw