Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
dbfe92c5
Unverified
Commit
dbfe92c5
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Log probably-ignorable SQLException just to be safe
parent
5209d6dc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/driver/mongo.clj
+8
-5
8 additions, 5 deletions
src/metabase/driver/mongo.clj
src/metabase/models/setting.clj
+4
-1
4 additions, 1 deletion
src/metabase/models/setting.clj
src/metabase/util.clj
+1
-43
1 addition, 43 deletions
src/metabase/util.clj
with
13 additions
and
49 deletions
src/metabase/driver/mongo.clj
+
8
−
5
View file @
dbfe92c5
...
...
@@ -66,14 +66,17 @@
(
cond
;; 1. url?
(
and
(
string?
field-value
)
(
u/url?
field-value
))
:type/URL
(
u/url?
field-value
))
:type/URL
;; 2. json?
(
and
(
string?
field-value
)
(
or
(
.startsWith
"{"
field-value
)
(
.startsWith
"["
field-value
)))
(
when-let
[
j
(
u/try-apply
json/parse-string
field-value
)]
(
when
(
or
(
map?
j
)
(
sequential?
j
))
:type/SerializedJSON
))))
(
.startsWith
"["
field-value
)))
(
when-let
[
j
(
u/ignore-exceptions
(
json/parse-string
field-value
))]
(
when
(
or
(
map?
j
)
(
sequential?
j
))
:type/SerializedJSON
))))
(
defn-
find-nested-fields
[
field-value
nested-fields
]
(
loop
[[
k
&
more-keys
]
(
keys
field-value
)
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/setting.clj
+
4
−
1
View file @
dbfe92c5
...
...
@@ -34,6 +34,7 @@
[
core
:as
core
]
[
string
:as
str
]]
[
clojure.core.memoize
:as
memoize
]
[
clojure.java.jdbc
:as
jdbc
]
[
clojure.tools.logging
:as
log
]
[
environ.core
:as
env
]
[
honeysql.core
:as
hsql
]
...
...
@@ -126,7 +127,9 @@
;; and ignore that Exception if one is thrown.
(
try
(
db/insert!
Setting
:key
settings-last-updated-key,
:value
(
hx/cast
:text
(
hsql/raw
"current_timestamp"
)))
(
catch
java.sql.SQLException
_
)))
(
catch
java.sql.SQLException
e
;; go ahead and log the Exception anyway on the off chance that it *wasn't* just a race condition issue
(
log/error
(
tru
"Error inserting new Setting:"
)
(
with-out-str
(
jdbc/print-sql-exception-chain
e
))))))
;; Now that we updated the value in the DB, go ahead and update our cached value as well, because we know about the
;; changes
(
swap!
cache
assoc
settings-last-updated-key
(
db/select-one-field
:value
Setting
:key
settings-last-updated-key
)))
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util.clj
+
1
−
43
View file @
dbfe92c5
...
...
@@ -4,9 +4,7 @@
[
data
:as
data
]
[
pprint
:refer
[
pprint
]]
[
string
:as
s
]]
[
clojure.java
[
classpath
:as
classpath
]
[
jdbc
:as
jdbc
]]
[
clojure.java.classpath
:as
classpath
]
[
clojure.math.numeric-tower
:as
math
]
[
clojure.tools.logging
:as
log
]
[
clojure.tools.namespace.find
:as
ns-find
]
...
...
@@ -15,7 +13,6 @@
[
puppetlabs.i18n.core
:as
i18n
:refer
[
trs
]]
[
ring.util.codec
:as
codec
])
(
:import
[
java.net
InetAddress
InetSocketAddress
Socket
]
java.sql.SQLException
[
java.text
Normalizer
Normalizer$Form
]))
;; This is the very first log message that will get printed. It's here because this is one of the very first
...
...
@@ -290,45 +287,6 @@
:when
(
re-find
#
"metabase"
s
)]
(
s/replace
s
#
"^metabase\."
""
))))})
(
defn
wrap-try-catch
"Returns a new function that wraps F in a `try-catch`. When an exception is caught, it is logged
with `log/error` and returns `nil`."
([
f
]
(
wrap-try-catch
f
nil
))
([
f
f-name
]
(
let
[
exception-message
(
if
f-name
(
format
"Caught exception in %s: "
f-name
)
"Caught exception: "
)]
(
fn
[
&
args
]
(
try
(
apply
f
args
)
(
catch
SQLException
e
(
log/error
(
format-color
'red
"%s\n%s\n%s"
exception-message
(
with-out-str
(
jdbc/print-sql-exception-chain
e
))
(
pprint-to-str
(
filtered-stacktrace
e
)))))
(
catch
Throwable
e
(
log/error
(
format-color
'red
"%s %s\n%s"
exception-message
(
or
(
.getMessage
e
)
e
)
(
pprint-to-str
(
filtered-stacktrace
e
))))))))))
(
defn
try-apply
"Like `apply`, but wraps F inside a `try-catch` block and logs exceptions caught.
(This is actaully more flexible than `apply` -- the last argument doesn't have to be
a sequence:
(try-apply vector :a :b [:c :d]) -> [:a :b :c :d]
(apply vector :a :b [:c :d]) -> [:a :b :c :d]
(try-apply vector :a :b :c :d) -> [:a :b :c :d]
(apply vector :a :b :c :d) -> Not ok - :d is not a sequence
This allows us to use `try-apply` in more situations than we'd otherwise be able to."
[
^
clojure.lang.IFn
f
&
args
]
(
apply
(
wrap-try-catch
f
)
(
concat
(
butlast
args
)
(
if
(
sequential?
(
last
args
))
(
last
args
)
[(
last
args
)]))))
(
defn
deref-with-timeout
"Call `deref` on a FUTURE and throw an exception if it takes more than TIMEOUT-MS."
[
futur
timeout-ms
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment