Skip to content

Commit b29a712

Browse files
committed
Dry suggestion: uses finally block to call histogram
1 parent c2d8704 commit b29a712

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

packages/core/src/mapping-kit/liquid-directive.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,22 @@ export function evaluateLiquid(liquidValue: any, event: any, statsContext?: Stat
7373
throw new Error('liquid template values are limited to 1000 characters')
7474
}
7575

76-
let res
76+
let res: string
7777
const start = Date.now()
78-
let duration
78+
let status: 'success' | 'fail' = 'success'
79+
7980
try {
8081
res = liquidEngine.parseAndRenderSync(liquidValue, event)
8182
} catch (e) {
82-
duration = Date.now() - start
83-
83+
status = 'fail'
84+
throw e
85+
} finally {
86+
const duration = Date.now() - start
8487
statsContext?.statsClient?.histogram('liquid.template.evaluation_ms', duration, [
8588
...statsContext.tags,
86-
`result:fail` // status = success/fail, not in the psudocode for simplicity
89+
`result:${status}`
8790
])
88-
throw e
8991
}
90-
duration = Date.now() - start
91-
92-
statsContext?.statsClient?.histogram('liquid.template.evaluation_ms', duration, [
93-
...statsContext.tags,
94-
`result:success` // status = success/fail, not in the psudocode for simplicity
95-
])
9692

9793
if (typeof res !== 'string') {
9894
return 'error'

0 commit comments

Comments
 (0)