Fork me on GitHub

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

Alex Miller (Clojure team)13: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.

Alex Miller (Clojure team)13:10:06

you might also be interested in 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 ?


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

metal 3

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


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


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


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.


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


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


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


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


ok, thank you


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


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.


missed immutability by that much 🙂

😅 3

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