Fork me on GitHub
#clojure
<
2019-11-04
>
fabrao00:11:29

Hello all, why my re-matches is getting StackOverflow?

fabrao00:11:47

I have a long string with re-matches it

hiredman00:11:44

Are you sure re-matches is stackoverflowing? If you are calling a function in repl there is potentially lots of other code invoked in printing the result for example

fabrao00:11:08

the only function I call is re-match and pass the string

fabrao00:11:34

well, about Repl I don´t know

fabrao00:11:14

is there any way to see jvm options in repl? Maybe seen the configuration about it

fabrao00:11:40

I´m using boot instead

hiredman00:11:50

Look at the stacktrack trace and see what code is on the stack

fabrao00:11:50

1. Unhandled java.lang.StackOverflowError
   (No message)

              Pattern.java: 4660  java.util.regex.Pattern$GroupHead/match
              Pattern.java: 4787  java.util.regex.Pattern$Loop/match
              Pattern.java: 4719  java.util.regex.Pattern$GroupTail/match
              Pattern.java: 4570  java.util.regex.Pattern$BranchConn/match
              Pattern.java: 3779  java.util.regex.Pattern$CharProperty/match
              Pattern.java: 4606  java.util.regex.Pattern$Branch/match
              Pattern.java: 4660  java.util.regex.Pattern$GroupHead/match
              Pattern.java: 4787  java.util.regex.Pattern$Loop/match
...

fabrao00:11:46

may be it´s been recursive inside it

fabrao00:11:09

not in recur tail mode

fabrao00:11:08

if I increase jvm memory

hiredman00:11:01

No, you need to increase the stacksize

hiredman00:11:47

Apparently it is a thing, on a large enough string the Java regex library will stackoverflow with certain regexs.

fabrao00:11:10

Do you know how to increase stacksize in boot ?

fabrao00:11:47

or other way to do this with regex?

hiredman00:11:38

The easiest thing to do might be to preprocess the string, split it in to smaller strings based on some separator(if nothing else splitting by lines), and then regex the smaller strings

dpsutton00:11:01

Could switching to instaparse and a grammar solve this? I imagine a full parser won’t be limited (as much) by the stack?

fabrao00:11:20

@dpsutton I know that instaparse is good for this too, but by regex is simple than that

dpsutton00:11:49

Well ... in theory :)

fabrao00:11:42

I did a parser with instaparser, but it´s much more complex than that 🙂

fabrao00:11:25

doing preprocess the string is an option too, I´ve done it, but I have some \r\n in the middle of string that will break the rule for spliting string

fabrao01:11:27

and I tried the regex expression in on-line test and it worked, but this problem happen

vlaaad09:11:12

Can I introduce my own reader conditional features in a library? like that: #?(:mylib/jdk8 old-and-busted-form :mylib/jdk11 new-hotness-form)

thheller10:11:20

you can but there is no way to activate them currently

vlaaad10:11:35

so basically I can't 😄

Alex Miller (Clojure team)12:11:50

You can’t unless you are in control of reading the source. That is, the reader supports it, the langs do not.

Alex Miller (Clojure team)12:11:17

There are several ways to do jdk-conditional code though - checking java system properties, or the presence of classes, etc

tdantas11:11:42

probably quite common issue when you start functional programming I’m trying to make my code more testable/functional and I wrote the gist (https://gist.github.com/tdantas/1daa70b780d80e51e86416eb7dcf95ac) to understand how would you guys transform the js imperative code into clojure (testable/idiomatic ) one my first approach was only using functions, my second one will be using protocols for ‘statefull’ components. is that make sense ?

Cas Shun12:11:48

I have a dependency that I wish to integrate with tools.deps, however it's an FTP only distro on a password protected server. Is there any sane way to automatically pull and add this to my classpath?

Alex Miller (Clojure team)12:11:17

If you have the jar locally, you can just use :local/root to refer to it as a dep

dpsutton13:11:53

would this be a good candidate for clojure.tools.deps.alpha.extensions for a person to extend tools.deps to handle FTP?

Alex Miller (Clojure team)13:11:46

one big thing is we want no creds in deps.edn files

dpsutton13:11:12

oh i meant for a user to personally extend, not for a patch to tools.deps. it seems open is why i was wondering

Alex Miller (Clojure team)13:11:49

it is open with the caveat that there currently is no way to get your code on the classpath when building classpaths

Alex Miller (Clojure team)13:11:15

if using tools.deps directly, then that's up to you of course

dominicm14:11:12

We need a deps.edn for our deps.edn.... :)

dangercoder14:11:06

Has anyone managed to wrap the java library Redisson in a nice way?

dangercoder15:11:26

I wrapped it myself, works for now.

roklenarcic15:11:30

Is there a way to specify exclusions in deps.edn dependencies?

dharrigan15:11:26

ch.qos.logback/logback-classic {:mvn/version "1.2.3" :exclusions [org.slf4j/slf4j-api]} as an example

dharrigan15:11:51

you're most welcome 🙂

jjttjj17:11:30

I have a library which wraps a java library and puts it into a big tree structure. The tree structure itself can be useful to end users for some situations. How do people feel about a library using something like datascript internally and exposing a datascript db of some static data? It feels wrong to me to do that and instead i've just used regular clojure to represent the tree, and have a namespace where i turn the tree into flat maps representing the "queries" i need for easy lookup in a query namespace. This works ok but as a user I keep wanting to use the tree in new ways which either requires repeating a lot of what's in the query namespace, or putting things in the query namespace which aren't used by the library. I feel like I'm slowly implementing a more datascript-like structure anyway.

darwin17:11:50

not sure if I understand your situation, but you could maybe think about exposing a thin wrapper over your java-tree-structure implementing clojure’s map abstraction

darwin17:11:37

@U04VDQDDY used this approach in to expose javascript objects to clojurescript users for interop here: https://github.com/mfikes/cljs-bean/blob/master/doc/overview.md

jjttjj17:11:39

I actually have that aspect of things working ok, that is, transforming the complex java objects to maps. I do this by using the structure of the class hierarchy. But the class hierarchy itself can be useful to expose (for example generating specs or datomic schema, things I would like to make possible but not directly include in the library). So I guess I'm wondering if this seems like a good use case for including/exposing datascript in a library, or if that's something that should be avoided? I haven't seen it done anywhere

darwin17:11:34

I don’t know

jjttjj17:11:08

fair enough 🙂

didibus19:11:04

Maybe your wrapper isn't useful in this case

didibus19:11:22

And you just shouldn't bother wrapping that Java library,but just have people use it directly?

didibus19:11:00

I say that because it sounds like you're saying there's just more and more things that the user might just want direct access to the Java structure

didibus19:11:39

That might mean you have an unnecessary abstraction

jjttjj19:11:00

the thing is the java library doesn't expose the structure usefully, my library creates it from a lot of reflection. The java library uses a bunch of "data classes" which can be modelled as just clojure maps, but they use individual classes which are a pain to create. They are often nested as well. Besides this there are ~150 methods that use various arrangements of this data as ordered arguments. My wrapper basically just reflects on this data to create a tree structure, and then uses that to implement clojure.data.java calls to translate to and from the java objects and clojure maps. And this gets me at feature parity with the Java api, but I think additional features could be added with the use of the structure data. (The low hanging fruit being specs/datomic schema).

jumpnbrownweasel20:11:41

If you made the tree structure available via datascript, would that allow you to remove a lot of the Clojure API? Smaller is better, if possible.

didibus19:11:04

Hum.. ya then if you do provide additional value I'd say that's good. If exposing DataScript provides even more value I'd say that's fine then. It's all going to be based on how much value you provide for the complexities or additional gotchas and dependencies that using your lib bring with it.

josh_tackett20:11:06

Anyone ever run an external API on a windows aws machine? Code works locally, but on the windows machine I'm getting the following error:

java.lang.NullPointerException: null
                               core.clj:151 compojure.core/routing[fn]
                              core.clj:2592 clojure.core/some
                              core.clj:2583 clojure.core/some
                               core.clj:151 compojure.core/routing
                               core.clj:148 compojure.core/routing
                            RestFn.java:139 clojure.lang.RestFn.applyTo
                               core.clj:648 clojure.core/apply
                               core.clj:641 clojure.core/apply
                               core.clj:156 compojure.core/routes[fn]

hiredman20:11:15

What do mean by works locally?

hiredman20:11:10

My wild guess is you are loading a resource as a file (from the filesystem) instead of as a resource (from the classpath), which works locally when the file is present, but when you package up your code and ship it off, you just ship the jar, so the file isn't on the filesystem

hiredman20:11:53

That isn't really based on your stacktrace there because the stacktrace is incomplete and it looks like you are using some library that is editing and omitting parts of it as well

hiredman20:11:51

That is the exception you would get if one of your handlers was the value nil instead of a ring handler

borkdude20:11:18

If I'm writing output to *err* I don't see it during lein test. What should I do to see that?

borkdude20:11:26

it works with clj test runner

hiredman21:11:07

how are you writing it?

hiredman21:11:13

I would expect that to just work, but maybe something like missing flushing when printing or something. I am however increasingly out of date on how stuff works with lein

hiredman21:11:12

if you are using pprint, definitely insert a flush afterwards, if youare using multiple threads, I think the lein runner injects a call to shutdown-agents at the end

hiredman21:11:11

oh, lein does its own manipulating of clojure.test/report, so who knows if the multimethod you register that method on is even being called

seancorfield21:11:55

You can tell lein not to monkey-patch clojure.test via some key in project.clj but, yeah, that's probably what's shooting you in the foot there.

borkdude21:11:30

ah alright. what's the downside of not letting lein monkey patching ?

bfabry21:11:17

breaks retest according to the docs. which I've never ever seen anyone use https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L356

bfabry21:11:57

neat idea though

chrisulloa21:11:01

In Python and Javascript, Github has a nice way of alerting you of known security vulnerabilities. Is there anything similar for Clojure? The only way I can think of to look for security patches is to manually read through changelogs of different libraries and decide which ones need to be upgraded.

chrisulloa21:11:25

It looks like Github scans https://cve.mitre.org/ for vulnerabilities in libraries

👍 4
Alex Miller (Clojure team)21:11:54

There are some java tools for this that work for java deps of Clojure

chrisulloa21:11:42

Ah okay, but I’m guessing for the Clojure libraries themselves there’s no centralized place to announce and discover security vulnerabilities I was looking at lein-nvd which looks through jars in the classpath and crosschecks the national vulnerability database

josh_tackett22:11:29

@hiredman If I run lein ring server-headless on my machine I can run a localhost curl and hit the server. When I do the same on the aws windows desktop machine, I get the null point after compojure core routing. Maybe something to do with the fact that it's an aws windows desktop machine?

hiredman22:11:28

running from lein vs. running from a jar file (is that how you deploy?) are different

hiredman22:11:06

my guess is it has nothing to do with the windows server, and your issue is something you are doing doesn't work when running from a jar

hiredman22:11:26

my example of a file system file vs. a resource from a classloader is an example of a difference

hiredman22:11:39

loading resources via the classloader will work for both, loading a file can be made to work for both, but won't without extra work so people often trip over it

hiredman22:11:13

that is a wild guess from where people often have trouble

hiredman22:11:58

working from what I have seen of your error, when you build your routes, one of the handlers you are building your routes out of is nil not a handler

josh_tackett22:11:13

Solved by setting the :host ring arg to the IP address of the windows server

josh_tackett22:11:25

Solved by setting the :host ring arg to the IP address of the windows server

josh_tackett23:11:15

@hiredman So I have a new error that seems like it's not compiling all the dependencies I need, which probably has to do with your other comment. It works when I run the system via a main method, but not working through the handler...

borkdude22:11:13

@hiredman @seancorfield it turned out not to be the monkey-patch issue, but lein test loads all namespaces and I had some defmethods elsewhere (to test if my lib wraps earlier registered defmethods correctly), but I didn't anticipate the loading order of leiningen

borkdude22:11:19

so now it works correctly with lein too

👍 8
alexbaranosky22:11:35

load order :face_with_symbols_on_mouth:

borkdude22:11:13

aaand found a test without assertions in one of my own projects: https://twitter.com/borkdude/status/1191482400599158785

❤️ 4
hiredman22:11:12

(is (= foo) bar) is the killer

andy.fingerhut22:11:06

Eastwood warns about that, I am pretty sure.

andy.fingerhut22:11:41

At least, I implemented something in it that caught several instances like that.

hiredman22:11:33

Oh yes, and Eastwood has caught it for me