Fork me on GitHub
#clojure
<
2020-10-01
>
g7s07:10:24

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) ?

alexmiller13:10:56

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.

alexmiller13:10:06

you might also be interested in https://github.com/scgilardi/slingshot which has a bunch of interesting facilities in this area

oly14:10:17

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 ?

lukasz15:10:45

In general GCP's Java SDK is pretty ok to use directly from Clojure (in my experience), so a wrapper is not necessary

3
peterschwarz15:10:25

You could ask over in #google-cloud. It’s not terribly active, but people seem to respond to questions

metal 3
oly15:10:55

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

lukasz17:10:34

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

lukasz17:10:40

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

emccue22:10:43

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

emccue22:10:18

I settled on just having maps with functions in them

emccue22:10:56

and having the public api just call those functions in the map

lukasz22:10:18

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

oly08:10:23

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.

Karo17:10:00

Hi all, how Unauthorizedaccessexception can be thrown in clojure? thanks

Toyam Cox17:10:57

but the exception you name seems to be a .Net thing

Karo18:10:01

Yes I can not find that exception, I tried to throw it using java lang esception class, this also doesn not work.

jimmy19:10:56

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

Karo07:10:56

(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.

Karo07:10:29

I am using clojure on the jvm.

jimmy13:10:38

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

Karo14:10:03

ok, thank you

g7s18:10:14

@alexmiller Thanks! I may look into slingshot to see if it fits my needs

borkdude21:10:47

I think even java exceptions are effectively immutable right?

borkdude21:10:39

hmm, it does have setStackTrace but not setMessage

borkdude21:10:16

> If the stack trace of this Throwable is not writable, calling this method has no effect other than validating its argument.

andy.fingerhut21:10:04

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.

andy.fingerhut21:10:08

missed immutability by that much 🙂

😅 3
borkdude21:10:34

I've tried mutating exceptions unsuccessfully before that's why I assumed they were immutable by design, but not quite

andy.fingerhut22:10:20

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.

andy.fingerhut22:10:17

Unless your goal is to get pedants like me into a discussion of what immutable really means 🙂

borkdude22:10:51

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 ;))

andy.fingerhut22:10:23

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.

borkdude22:10:59

I think more people are happy with being able to hack around private then the other way around in Clojure