polylith

timo 2024-03-18T10:41:53.783819Z

Hi, are you guys using exceptions for your components or are you using something different if something goes wrong?

namenu 2024-03-18T13:29:01.267579Z

Once we used failjure, now it’s gone and we decided to use ex-info

namenu 2024-03-18T13:31:47.870349Z

Really promising alternative to me is missionary. With this approach we can finally make every components “pure”

👍 1
seancorfield 2024-03-18T15:10:59.734789Z

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

👍 3
seancorfield 2024-03-18T15:12:18.093749Z

You're on the JVM: lots of code you might call can throw exceptions; they are idiomatic on the JVM.

👍 1
1
2024-03-23T23:39:32.399419Z

we use ex-info with a data that conforms to https://github.com/cognitect-labs/anomalies

2024-03-23T23:40:30.699299Z

if you’re writing higher performance code, and/or have a very large project , i also like https://github.com/redplanetlabs/defexception

👍 1
namenu 2024-03-18T13:26:59.174679Z

is there a way to return error with poly info when there is any warnings? I want it to be checked by CI.

👍 1
tengstrand 2024-03-18T14:35:33.650409Z

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.

👍 1
seancorfield 2024-03-18T15:00:41.897919Z

You can do it with poly check via the API in 0.2.19. We do it at work in our build.clj file

seancorfield 2024-03-18T15:01:20.693539Z

As soon as I get to my desk, I'll share the code

seancorfield 2024-03-18T15:14:03.726289Z

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.

❤️ 3
seancorfield 2024-03-18T15:14:38.909089Z

We :require [polylith.clj.core.api.interface :as poly] in the build ns.

namenu 2024-03-19T00:31:13.452749Z

Thanks! I’ll copy and paste that code right away

😁 1
namenu 2024-04-29T05:27:22.566639Z

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

tengstrand 2024-04-29T06:19:37.899539Z

An option would be to make this configurable.

seancorfield 2024-04-29T06:22:39.282099Z

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

tengstrand 2024-04-29T06:24:42.524319Z

Do you mean it doesn’t populate :messages or that it doesn’t return a code (e.g. 1)?

seancorfield 2024-04-29T06:26:21.964869Z

It returns a hash map with :ok? and :error-messages etc.

seancorfield 2024-04-29T06:27:04.426239Z

See the poly-check function I posted above, from our build.clj file at work.

tengstrand 2024-04-29T06:30:43.974809Z

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.

seancorfield 2024-04-29T06:34:01.413079Z

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.

namenu 2024-04-29T06:42:35.252089Z

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

tengstrand 2024-04-29T06:43:04.550939Z

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.

seancorfield 2024-04-29T06:50:45.394579Z

That would be nice. So callers could check whether any warnings came back when :ok? is truthy. I'd like that.

tengstrand 2024-04-29T06:52:45.205019Z

Yes, that's my idea. We could add :has-warnings? or similar too.