mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 16:36:38 +02:00
🐛 Improve not-found error report on s3 storage backend
This commit is contained in:
parent
b582998228
commit
9b59b92464
3 changed files with 43 additions and 17 deletions
|
@ -51,6 +51,7 @@
|
||||||
software.amazon.awssdk.services.s3.model.DeleteObjectsRequest
|
software.amazon.awssdk.services.s3.model.DeleteObjectsRequest
|
||||||
software.amazon.awssdk.services.s3.model.DeleteObjectsResponse
|
software.amazon.awssdk.services.s3.model.DeleteObjectsResponse
|
||||||
software.amazon.awssdk.services.s3.model.GetObjectRequest
|
software.amazon.awssdk.services.s3.model.GetObjectRequest
|
||||||
|
software.amazon.awssdk.services.s3.model.NoSuchKeyException
|
||||||
software.amazon.awssdk.services.s3.model.ObjectIdentifier
|
software.amazon.awssdk.services.s3.model.ObjectIdentifier
|
||||||
software.amazon.awssdk.services.s3.model.PutObjectRequest
|
software.amazon.awssdk.services.s3.model.PutObjectRequest
|
||||||
software.amazon.awssdk.services.s3.model.S3Error
|
software.amazon.awssdk.services.s3.model.S3Error
|
||||||
|
@ -126,17 +127,19 @@
|
||||||
(defmethod impl/get-object-data :s3
|
(defmethod impl/get-object-data :s3
|
||||||
[backend object]
|
[backend object]
|
||||||
(us/assert! ::backend backend)
|
(us/assert! ::backend backend)
|
||||||
(letfn [(no-such-key? [cause]
|
|
||||||
(instance? software.amazon.awssdk.services.s3.model.NoSuchKeyException cause))
|
(let [result (p/await (get-object-data backend object))]
|
||||||
(handle-not-found [cause]
|
(if (ex/exception? result)
|
||||||
|
(cond
|
||||||
|
(ex/instance? NoSuchKeyException result)
|
||||||
(ex/raise :type :not-found
|
(ex/raise :type :not-found
|
||||||
:code :object-not-found
|
:code :object-not-found
|
||||||
:hint "s3 object not found"
|
:hint "s3 object not found"
|
||||||
:cause cause))]
|
:cause result)
|
||||||
|
:else
|
||||||
|
(throw result))
|
||||||
|
|
||||||
(-> (get-object-data backend object)
|
result)))
|
||||||
(p/catch no-such-key? handle-not-found)
|
|
||||||
(p/await!))))
|
|
||||||
|
|
||||||
(defmethod impl/get-object-bytes :s3
|
(defmethod impl/get-object-bytes :s3
|
||||||
[backend object]
|
[backend object]
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
funcool/tubax {:mvn/version "2021.05.20-0"}
|
funcool/tubax {:mvn/version "2021.05.20-0"}
|
||||||
funcool/cuerdas {:mvn/version "2023.11.09-407"}
|
funcool/cuerdas {:mvn/version "2023.11.09-407"}
|
||||||
funcool/promesa {:git/sha "484b7f5c0d08d817746caa685ed9ac5583eb37fa"
|
funcool/promesa {:git/sha "0c5ed6ad033515a2df4b55addea044f60e9653d0"
|
||||||
:git/url "https://github.com/funcool/promesa"}
|
:git/url "https://github.com/funcool/promesa"}
|
||||||
|
|
||||||
funcool/datoteka {:mvn/version "3.0.66"
|
funcool/datoteka {:mvn/version "3.0.66"
|
||||||
|
|
|
@ -7,10 +7,12 @@
|
||||||
(ns app.common.exceptions
|
(ns app.common.exceptions
|
||||||
"A helpers for work with exceptions."
|
"A helpers for work with exceptions."
|
||||||
#?(:cljs (:require-macros [app.common.exceptions]))
|
#?(:cljs (:require-macros [app.common.exceptions]))
|
||||||
|
(:refer-clojure :exclude [instance?])
|
||||||
(:require
|
(:require
|
||||||
#?(:clj [clojure.stacktrace :as strace])
|
#?(:clj [clojure.stacktrace :as strace])
|
||||||
[app.common.pprint :as pp]
|
[app.common.pprint :as pp]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[clojure.core :as c]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[expound.alpha :as expound])
|
[expound.alpha :as expound])
|
||||||
|
@ -20,6 +22,9 @@
|
||||||
|
|
||||||
#?(:clj (set! *warn-on-reflection* true))
|
#?(:clj (set! *warn-on-reflection* true))
|
||||||
|
|
||||||
|
(def ^:dynamic *data-length* 8)
|
||||||
|
(def ^:dynamic *data-level* 8)
|
||||||
|
|
||||||
(defmacro error
|
(defmacro error
|
||||||
[& {:keys [type hint] :as params}]
|
[& {:keys [type hint] :as params}]
|
||||||
`(ex-info ~(or hint (name type))
|
`(ex-info ~(or hint (name type))
|
||||||
|
@ -49,20 +54,38 @@
|
||||||
|
|
||||||
(defn ex-info?
|
(defn ex-info?
|
||||||
[v]
|
[v]
|
||||||
(instance? #?(:clj clojure.lang.IExceptionInfo :cljs cljs.core.ExceptionInfo) v))
|
(c/instance? #?(:clj clojure.lang.IExceptionInfo :cljs cljs.core.ExceptionInfo) v))
|
||||||
|
|
||||||
(defn error?
|
(defn error?
|
||||||
[v]
|
[v]
|
||||||
(instance? #?(:clj clojure.lang.IExceptionInfo :cljs cljs.core.ExceptionInfo) v))
|
(c/instance? #?(:clj clojure.lang.IExceptionInfo :cljs cljs.core.ExceptionInfo) v))
|
||||||
|
|
||||||
(defn exception?
|
(defn exception?
|
||||||
[v]
|
[v]
|
||||||
(instance? #?(:clj java.lang.Throwable :cljs js/Error) v))
|
(c/instance? #?(:clj java.lang.Throwable :cljs js/Error) v))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn runtime-exception?
|
(defn runtime-exception?
|
||||||
[v]
|
[v]
|
||||||
(instance? RuntimeException v)))
|
(c/instance? RuntimeException v)))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(defn instance?
|
||||||
|
[class cause]
|
||||||
|
(loop [cause cause]
|
||||||
|
(if (c/instance? class cause)
|
||||||
|
true
|
||||||
|
(if-let [cause (ex-cause cause)]
|
||||||
|
(recur cause)
|
||||||
|
false)))))
|
||||||
|
|
||||||
|
;; NOTE: idea for a macro for error handling
|
||||||
|
;; (pu/try-let [cause (p/await (get-object-data backend object))]
|
||||||
|
;; (ex/instance? NoSuchKeyException cause)
|
||||||
|
;; (ex/raise :type :not-found
|
||||||
|
;; :code :object-not-found
|
||||||
|
;; :hint "s3 object not found"
|
||||||
|
;; :cause cause))
|
||||||
|
|
||||||
(defn explain
|
(defn explain
|
||||||
[data & {:as opts}]
|
[data & {:as opts}]
|
||||||
|
@ -91,8 +114,8 @@
|
||||||
data? true
|
data? true
|
||||||
explain? true
|
explain? true
|
||||||
chain? true
|
chain? true
|
||||||
data-length 8
|
data-length *data-length*
|
||||||
data-level 5}}]
|
data-level *data-level*}}]
|
||||||
|
|
||||||
(letfn [(print-trace-element [^StackTraceElement e]
|
(letfn [(print-trace-element [^StackTraceElement e]
|
||||||
(let [class (.getClassName e)
|
(let [class (.getClassName e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue