This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-18
Channels
- # announcements (1)
- # babashka (17)
- # beginners (26)
- # calva (7)
- # clj-kondo (57)
- # cljdoc (8)
- # clojure (6)
- # clojure-europe (26)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (52)
- # clojure-uk (4)
- # datahike (1)
- # emacs (16)
- # events (1)
- # hyperfiddle (24)
- # introduce-yourself (1)
- # jobs (8)
- # lsp (6)
- # malli (9)
- # membrane (38)
- # missionary (5)
- # polylith (26)
- # portal (4)
- # reitit (1)
- # releases (7)
- # remote-jobs (1)
Hi, are you guys using exceptions for your components or are you using something different if something goes wrong?
Really promising alternative to me is missionary. With this approach we can finally make every components “pure”
My answer is the same regardless of Polylith: • for unexpected errors that local code cannot handle, throw an exception • for "expected" errors / failures that can be handled in local code, return some sort of error code or pair/hash map with either a successful result or details of the failure
You're on the JVM: lots of code you might call can throw exceptions; they are idiomatic on the JVM.
we use ex-info with a data that conforms to https://github.com/cognitect-labs/anomalies
if you’re writing higher performance code, and/or have a very large project , i also like https://github.com/redplanetlabs/defexception
is there a way to return error with poly info
when there is any warnings? I want it to be checked by CI.
We don’t support that today, but we could e.g. activate it by passing in something like :with-warnings to the info command. You can create an issue if you want.
You can do it with poly check via the API in 0.2.19. We do it at work in our build.clj file
As soon as I get to my desk, I'll share the code
This is what we have in our build.clj
file:
(defn poly-check
"Run the Polylith check command."
[opts]
(let [{:keys [ok? error-messages]} (poly/check)]
(when-not ok?
(doseq [{:keys [code colorized-message type]} error-messages]
(println colorized-message ":" type code))
(throw (ex-info "Polylith Check Failed!" {}))))
opts)
so clojure -T:build poly-check
will fail the build if there are errors/warnings.We :require [polylith.clj.core.api.interface :as poly]
in the build
ns.
poly/check
doesn't catch warnings so I ended up like this.
- name: Check poly info
run: |
output=$(clojure -M:poly info color-mode:none)
if echo "$output" | grep -q "Warning"; then
warnings=$(echo "$output" | sed -n '/Warning/,$p')
while IFS= read -r line; do
echo "::warning::$line"
done <<< "$warnings"
exit 1
fi
An option would be to make this configurable.
I'm a bit surprised that poly/check
doesn't return warnings in that data structure -- guess I hadn't noticed (and failing on errors has been sufficient so far for us)?
Do you mean it doesn’t populate :messages or that it doesn’t return a code (e.g. 1)?
It returns a hash map with :ok?
and :error-messages
etc.
See the poly-check
function I posted above, from our build.clj
file at work.
Okay, then I think we understand each other! This could of course be configurable with something like treat-warning-as-error
and then if we have a warning when running the test command, it could e.g. return with 1.
I don't think we do understand each other.
In the API does the check
function return warnings or just errors? Is :ok?
still truthy in the presence of warnings?
I'm not asking about anything else except that API function.
In the API does the check
function return warnings or just errors?
=> just errors
Is :ok?
still truthy in the presence of warnings?
=> yes
--
The validator that poly/check depends on only provides an interface for errors I guess.
https://github.com/polyfy/polylith/blob/338b36f724c899e4fe994eb9d3dae9a37f04bd46/components/validator/src/polylith/clj/core/validator/core.clj
Okay, get it now. We only return errors right now. One solution could be to also include the warnings. The :ok?
flag could work as today and be set if there are any errors.
That would be nice. So callers could check whether any warnings came back when :ok?
is truthy. I'd like that.
Yes, that's my idea. We could add :has-warnings?
or similar too.