I see. I’m fairly new to clojure. So I don’t know too much on the java ‘libraries’… Do I need to require a certain namespace to use ManagementFactory
?
you need to import the class
are you running in a repl or do you have a file with a ns
at the top?
ns
at the top
okay add
(ns whatever
(:require [] ...)
(:import (java.lang.management ManagementFactory)))
damn didn’t know you can do that! I guess thats one of the beauties of Clojure. So whatever is in the Oracle docs thats java, I can import and use that?
I really appreciate your help tonight! I can move forward and run with this!
yeah, all of clojure maps to the "java metaphysics" in some way
and you can import and use any classes you want
though certain things will be easier than others - "spring-like" stuff with annotations or stuff that reflectively calls constructors can be a pain
I’ve just been using the core library, and its all that I’ve needed so far. But now its a whole new world! lol
This might have been asked before but what is the clojure way to catch an ex-info and rethrow it with augmented ex-data (while not changing other parts of the exception) ?
ExceptionInfo objects are immutable, so it's not possible to actually augment the original exception object. You can pull out the message, data, and if desired, stack trace, and make a new ex-info though and throw that. The message and data are pretty obvious but you can use .getStackTrace and .setStackTrace to transfer that.
you might also be interested in https://github.com/scgilardi/slingshot which has a bunch of interesting facilities in this area
any decent libraries for GCP in particular I want to use cloud storage I see we have amazonica and aws-api's for amazon cloud but not seeing anything that seems as upto date or as comprehensive, anyone have any experience in this area ?
Thanks for the info, we have moved from AWS to GCP a while back but not tying your apps to any infrastructure makes moving between them much simpler, quite likely we will re asses which is better for us at some point.
In general GCP's Java SDK is pretty ok to use directly from Clojure (in my experience), so a wrapper is not necessary
You could ask over in #google-cloud. It’s not terribly active, but people seem to respond to questions
okay good to know, I was hoping to find a storages client that did aws cloud storage spaces and minio all in one so the service is not tied to a platform
If it helps - Minio can act as a proxy for google cloud storage, so you can use a S3 client, talk to minio and that will translate API calls from S3-style to Google Cloud
I'm pretty sure a universal client for Mino, S3 and Google Cloud doesn't exist in Clojure - but it's not hard to implement using protocols etc. We had one, but eventually we settled 100% on S3 and use Minio only in CI
Hi all, how Unauthorizedaccessexception can be thrown in clojure? thanks
(defn execute-study-header-get [study_uuid study_id database_id param]
(let [sponsor_id (str (get-sponsor-config param))
study-selections (get-study-selections-with-forecasts sponsor_id)
data (map (fn [x] (dissoc x :sponsorName :projectName :studyStatus :phase :indication
:forecastID :forecastName)) (:data study-selections))
result (map (fn [input] (and (= (:studyID input) study_id)
(= (:databaseID input) database_id)
(= (:UUID input) study_uuid))
) data)
check (some #(= % true) result)]
(if (not= check true) "401" (execute-study-header study_uuid study_id database_id))))
My task is to throw UnauthorizedAccessException 401 instead of string "401" in the last line of the code.
I am using clojure on the jvm.
Is this is some assignment? If so you should ask the person who gave it to you for clarification. There is no built-in exception called UnauthorizedAccessException. So you can use ex-info or you can make a custom exception. https://stackoverflow.com/questions/3835331/custom-exceptions-in-clojure
ok, thank you
but the exception you name seems to be a .Net thing
Yes I can not find that exception, I tried to throw it using java lang esception class, this also doesn not work.
@alexmiller Thanks! I may look into slingshot to see if it fits my needs
If you could put the exact code you tried, that might be helpful for people to know what you are looking for. UnauthorizedAccessException is not a part of the JVM but of the CLR (.Net). Are you using clojure on the jvm? If so, do you have the full name of the exception you want to throw? Do you need to throw a specific exception, or just want an exception to communicate a particular message? If the latter, try out https://clojuredocs.org/clojure.core/ex-info
I think even java exceptions are effectively immutable right?
hmm, it does have setStackTrace
but not setMessage
> If the stack trace of this Throwable is not writable, calling this method has no effect other than validating its argument.
Also initCause, which docs say is typically called within the constructor, but if not, it can be called at most once per Throwable object after construction.
thanks.
missed immutability by that much 🙂
I've tried mutating exceptions unsuccessfully before that's why I assumed they were immutable by design, but not quite
Then of course there is the "peeking under the Clojure API covers" kind of cheating where you can mutate Clojure collections, to no good effect.
Unless your goal is to get pedants like me into a discussion of what immutable really means 🙂
Reminds me of "private is a state of mind" by Alex Miller. Probably immutability is as well, although Clojure does quite a good job to enforce it (better than private ;))
I'm not multi cloud or anything - I just have a local/test impl for stuff - but even protocols might be overkill depending on the task
I settled on just having maps with functions in them
and having the public api just call those functions in the map
I haven't heard that quote before, but yeah, that is also sure to raise discussion among developers who like stronger language-enforcable gaurantees on information hiding.
I think more people are happy with being able to hack around private then the other way around in Clojure
Sure that works too. We use records+protocols because we use Component and we model api clients as components too - including S3 and such. Just makes it easier to manage dependencies of things