Skip to content

Commit

Permalink
Expose planner failure details on error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Dec 5, 2024
1 parent cf34e13 commit 690c603
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- BREAKING: Error from plan now envelops the graph value to avoid printing too much. You need to deref the value to get it now.
- BREAKING: Removed usage of `processor-error`, now the runner will not wrap the errors, this will generate simpler errors.
- Expose query and entity on errors during eql interface calls
- Expose planner failure details on error message

## [2024.11.23-alpha]
- Fix placeholders using different parameters
Expand Down
27 changes: 18 additions & 9 deletions src/main/com/wsscode/pathom3/connect/planner.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,14 @@
[k cause])))
missing))

(defn unreachable-detail-string [_env attr cause]
(case (::unreachable-cause cause)
::unreachable-cause-unknown-attribute
(str "- Attribute " attr " is unknown, there is not any resolver that outputs it.")

::unreachable-cause-missing-dependencies
(str "- Attribute " attr " dependencies can't be met, details: WIP")))

(defn verify-plan!*
[env
{::keys [unreachable-paths]
Expand All @@ -1710,15 +1718,16 @@
missing (pfsd/intersection unreachable-paths user-required)]
(if (seq missing)
(throw
(ex-info
(str "Pathom can't find a path for the following elements in the query: "
(pr-str (pfsd/shape-descriptor->query missing)) (p.path/at-path-string env))
{::graph-fn (fn [] graph)
::unreachable-paths missing
::unreachable-details (unreachable-details env graph missing)
::p.path/path (get env ::p.path/path)
:com.wsscode.pathom3.error/phase ::plan
:com.wsscode.pathom3.error/cause :com.wsscode.pathom3.error/attribute-unreachable}))
(let [details (unreachable-details env graph missing)]
(ex-info
(str "Pathom can't find a path for the following elements in the query" (p.path/at-path-string env) ":\n"
(str/join "\n" (map #(unreachable-detail-string env (key %) (val %)) details)))
{::graph-fn (fn [] graph)
::unreachable-paths missing
::unreachable-details details
::p.path/path (get env ::p.path/path)
:com.wsscode.pathom3.error/phase ::plan
:com.wsscode.pathom3.error/cause :com.wsscode.pathom3.error/attribute-unreachable})))
graph))
graph))

Expand Down
32 changes: 19 additions & 13 deletions test/com/wsscode/pathom3/connect/planner_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@
(deftest compute-run-graph-no-path-test
(testing "no path"
(check (=> {:ex/message
"Pathom can't find a path for the following elements in the query: [:a]"
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :a is unknown, there is not any resolver that outputs it.")

:ex/data
{::pcp/unreachable-paths {:a {}}
Expand All @@ -266,7 +268,9 @@
::eql/query [:a]})))

(check (=> {:ex/message
"Pathom can't find a path for the following elements in the query: [:a :b]"
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :a is unknown, there is not any resolver that outputs it.\n- Attribute :b is unknown, there is not any resolver that outputs it.")

:ex/data
{::pcp/unreachable-paths {:a {} :b {}}
Expand All @@ -280,7 +284,9 @@

(testing "broken chain"
(check (=> {:ex/message
"Pathom can't find a path for the following elements in the query: [:b]"
(str
"Pathom can't find a path for the following elements in the query:\n"
"- Attribute :b dependencies can't be met, details: WIP")

:ex/data
{::pcp/unreachable-paths {:b {}}
Expand All @@ -295,14 +301,14 @@

(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:b]"
#"Pathom can't find a path for the following elements in the query:\n- Attribute :b dependencies can't be met, details: WIP"
(compute-run-graph
{::pci/index-oir '{:b {{:a {}} #{b1 b}}}
::eql/query [:b]})))

(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:b]"
#"Pathom can't find a path for the following elements in the query:\n- Attribute :b dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'a
::pco/output [:a]}
Expand All @@ -314,7 +320,7 @@

(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:c]"
#"Pathom can't find a path for the following elements in the query:\n- Attribute :c dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
Expand All @@ -326,7 +332,7 @@

(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:c]"
#"Pathom can't find a path for the following elements in the query:\n- Attribute :c dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'b
::pco/input [:a]
Expand Down Expand Up @@ -714,7 +720,7 @@
(testing "nested cycles"
(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:b]"
#"Pathom can't find a path for the following elements in the query at path \[:a]:\n- Attribute :b dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'cycle-a
::pco/output [:a]}
Expand All @@ -725,7 +731,7 @@

(is (thrown-with-msg?
#?(:clj Throwable :cljs js/Error)
#"Pathom can't find a path for the following elements in the query: \[:c]"
#"Pathom can't find a path for the following elements in the query at path \[:a]:\n- Attribute :c dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'cycle-a
::pco/output [:a]}
Expand Down Expand Up @@ -1257,7 +1263,7 @@
(testing "nested plan failure"
(is (thrown-with-msg?
#?(:clj Throwable :cljs :default)
#"Pathom can't find a path for the following elements in the query: \[:c] at path \[:a]"
#"Pathom can't find a path for the following elements in the query at path \[:a]:\n- Attribute :c is unknown, there is not any resolver that outputs it."
(compute-run-graph
{::resolvers [{::pco/op-name 'nested-provider
::pco/output [{:a [:b]}]}
Expand All @@ -1274,7 +1280,7 @@
(is
(thrown-with-msg?
#?(:clj Throwable :cljs :default)
#"Pathom can't find a path for the following elements in the query: \[:child] at path \[:parent]"
#"Pathom can't find a path for the following elements in the query at path \[:parent]:\n- Attribute :child dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'parent
::pco/output [{:parent [:foo]}]}
Expand All @@ -1287,7 +1293,7 @@
(is
(thrown-with-msg?
#?(:clj Throwable :cljs :default)
#"Pathom can't find a path for the following elements in the query: \[:child-dep] at path \[:parent]"
#"Pathom can't find a path for the following elements in the query at path \[:parent]:\n- Attribute :child-dep dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'parent
::pco/output [{:parent [:foo]}]}
Expand All @@ -1303,7 +1309,7 @@
(is
(thrown-with-msg?
#?(:clj Throwable :cljs :default)
#"Pathom can't find a path for the following elements in the query: \[:child] at path \[:parent]"
#"Pathom can't find a path for the following elements in the query at path \[:parent]:\n- Attribute :child dependencies can't be met, details: WIP"
(compute-run-graph
{::resolvers [{::pco/op-name 'parent
::pco/output [{:parent [:foo]}]}
Expand Down

0 comments on commit 690c603

Please sign in to comment.