From 5888d70801e818c02bc67c371339f2b379e969d4 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 17:31:47 +0200 Subject: [PATCH 1/6] Catch exceptions during token value formatting --- src/clj/commiteth/routes/services.clj | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index d813962..43f1458 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -146,7 +146,11 @@ (defn prettify-bounty-items [bounty-items] - (let [renames {:user_name :display-name + (let [format-float (fn [balance] + (try + (format "%.2f" balance) + (catch java.util.IllegalFormatConversionException ex "0.00"))) + renames {:user_name :display-name :user_avatar_url :avatar-url :issue_title :issue-title :type :item-type @@ -164,7 +168,7 @@ (update :tokens (fn [tokens] (into {} (map (fn [[tla balance]] - [tla (format "%.2f" balance)]) + [tla (format-float balance)]) tokens))))) bounty-items))) From a7e2b60d833e540e8ed4f6cf3df919ff2a6536e8 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 17:35:38 +0200 Subject: [PATCH 2/6] Force convert long to float --- src/clj/commiteth/routes/services.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 43f1458..280ea7a 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -148,8 +148,8 @@ (defn prettify-bounty-items [bounty-items] (let [format-float (fn [balance] (try - (format "%.2f" balance) - (catch java.util.IllegalFormatConversionException ex "0.00"))) + (format "%.2f" (float balance)) + (catch Exception ex "0.00"))) renames {:user_name :display-name :user_avatar_url :avatar-url :issue_title :issue-title From ca5b7d7e7b407e9bb012e10fc3cacf746636438f Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 17:55:25 +0200 Subject: [PATCH 3/6] Log error message if token value cannot be parsed --- src/clj/commiteth/routes/services.clj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 280ea7a..9620b59 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -149,7 +149,10 @@ (let [format-float (fn [balance] (try (format "%.2f" (float balance)) - (catch Exception ex "0.00"))) + (catch Exception ex + (do + (log/error "Failed to convert token value:" balance) + "0.00")))) renames {:user_name :display-name :user_avatar_url :avatar-url :issue_title :issue-title From 36e4868294a68f88b025d6d0c7a127e809e99cc2 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 17:56:38 +0200 Subject: [PATCH 4/6] Substitute Exception with Throwable --- src/clj/commiteth/routes/services.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index 9620b59..cfd8f51 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -149,7 +149,7 @@ (let [format-float (fn [balance] (try (format "%.2f" (float balance)) - (catch Exception ex + (catch Throwable ex (do (log/error "Failed to convert token value:" balance) "0.00")))) From 34f3913ff489d4ff9ef2dcedb3ba3d04a7483903 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 17:58:19 +0200 Subject: [PATCH 5/6] Use implicit do in catch --- src/clj/commiteth/routes/services.clj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index cfd8f51..e7b8f52 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -150,9 +150,8 @@ (try (format "%.2f" (float balance)) (catch Throwable ex - (do - (log/error "Failed to convert token value:" balance) - "0.00")))) + (log/error "Failed to convert token value:" balance) + "0.00"))) renames {:user_name :display-name :user_avatar_url :avatar-url :issue_title :issue-title From e540bd04ac7da7d2bf2543d5bb127193e13ded48 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Mon, 12 Mar 2018 18:21:49 +0200 Subject: [PATCH 6/6] Log issue details along with wrong token balance --- src/clj/commiteth/routes/services.clj | 52 +++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/clj/commiteth/routes/services.clj b/src/clj/commiteth/routes/services.clj index e7b8f52..435b172 100644 --- a/src/clj/commiteth/routes/services.clj +++ b/src/clj/commiteth/routes/services.clj @@ -146,32 +146,40 @@ (defn prettify-bounty-items [bounty-items] - (let [format-float (fn [balance] - (try - (format "%.2f" (float balance)) - (catch Throwable ex - (log/error "Failed to convert token value:" balance) - "0.00"))) - renames {:user_name :display-name - :user_avatar_url :avatar-url - :issue_title :issue-title - :type :item-type - :repo_name :repo-name - :repo_owner :repo-owner - :issue_number :issue-number - :value_usd :value-usd - :claim_count :claim-count - :balance_eth :balance-eth - :user_has_address :user-has-address}] + (let [format-float (fn [bounty balance] + (try + (format "%.2f" (double balance)) + (catch Throwable ex + (log/error (str (:repo-owner bounty) + "/" + (:repo-name bounty) + "/" + (:issue-number bounty)) + "Failed to convert token value:" balance) + "0.00"))) + update-token-values (fn [bounty] + (->> bounty + :tokens + (map (fn [[tla balance]] + [tla (format-float bounty balance)])) + (into {}) + (assoc bounty :tokens))) + renames {:user_name :display-name + :user_avatar_url :avatar-url + :issue_title :issue-title + :type :item-type + :repo_name :repo-name + :repo_owner :repo-owner + :issue_number :issue-number + :value_usd :value-usd + :claim_count :claim-count + :balance_eth :balance-eth + :user_has_address :user-has-address}] (map #(-> % (rename-keys renames) (update :value-usd usd-decimal->str) (update :balance-eth eth-decimal->str) - (update :tokens (fn [tokens] - (into {} - (map (fn [[tla balance]] - [tla (format-float balance)]) - tokens))))) + update-token-values) bounty-items))) (defn activity-feed []