fix(type-generator): treat empty/un-rendered definitions.json as no metric views - #493
fix(type-generator): treat empty/un-rendered definitions.json as no metric views#493keugenek wants to merge 1 commit into
Conversation
…etric views
readMetricConfig threw a fatal "Failed to parse definitions.json" whenever the
file was empty or still held its Go-template guard. The template ships
config/metric-views/definitions.json wrapped in `{{if .plugins.analytics}}`, so:
- scaffolding an app WITHOUT the analytics plugin renders an empty file, and
- running typegen against the raw template (e.g. an `npm install` postinstall
warmup before `appkit setup`) leaves the literal `{{...}}` in place.
Both are "no metric views defined", not misconfiguration — but JSON.parse("")
(or on `{{`) threw and aborted `appkit generate-types`, breaking `npm install`
for any analytics-off app and any tooling that warms the raw template.
Treat empty/whitespace-only or un-rendered (`{{`-prefixed) content the same as
an absent file (return null), matching the documented additive contract. A
non-empty, rendered file with genuinely malformed JSON still throws loudly.
Added mv-registry tests for the empty, whitespace-only, and un-rendered cases.
Co-authored-by: Isaac
📦 Bundle size reportCompared against
|
| dist | raw | gzip |
|---|---|---|
| JS (runtime) | 791 KB (+562 B) | 277 KB (+248 B) |
| Type declarations | 285 KB | 97 KB |
| Source maps | 1.5 MB (+921 B) | 515 KB (+355 B) |
| Other | 11 KB | 3.7 KB |
| Total | 2.6 MB (+1.4 KB) | 892 KB (+603 B) |
Per-entry composition (own code — deps external (as shipped))
| Entry | Initial (gz) | Lazy (gz) | Total (gz) | node_modules (min) | Own code (min) |
|---|---|---|---|---|---|
. |
86 KB (+9 B) | 2.5 KB | 89 KB (+9 B) | external | 281 KB (+57 B) |
./beta |
40 KB | 231 B | 40 KB | external | 119 KB |
./type-generator |
19 KB (+12 B) | 0 B | 19 KB (+12 B) | external | 54 KB (+57 B) |
Chunks:
| Entry | Chunk | Load | Size (gz) |
|---|---|---|---|
. |
index.js |
initial | 82 KB |
. |
utils.js |
initial | 4.0 KB |
. |
remote-tunnel-manager.js |
lazy | 2.5 KB |
./beta |
beta.js |
initial | 30 KB |
./beta |
databricks.js |
initial | 5.8 KB |
./beta |
service-context.js |
initial | 3.2 KB |
./beta |
client-options.js |
initial | 220 B |
./beta |
databricks.js |
lazy | 128 B |
./beta |
index.js |
lazy | 103 B |
./type-generator |
index.js |
initial | 19 KB |
@databricks/appkit-ui
npm tarball (packed): 305 KB — gzipped download (dist + bin; excludes release-only docs/NOTICE).
| dist | raw | gzip |
|---|---|---|
| JS (runtime) | 359 KB | 119 KB |
| Type declarations | 205 KB | 74 KB |
| Source maps | 685 KB | 224 KB |
| CSS | 16 KB | 3.3 KB |
| Total | 1.2 MB | 421 KB |
Per-entry composition (consumer bundle — deps bundled, peerDeps external)
| Entry | Initial (gz) | Lazy (gz) | Total (gz) | node_modules (min) | Own code (min) |
|---|---|---|---|---|---|
./js |
4.3 KB | 49 KB | 54 KB | 208 KB | 12 KB |
./js/beta |
20 B | 0 B | 20 B | 0 B | 0 B |
./react |
429 KB | 49 KB | 478 KB | 1.3 MB | 168 KB |
./react/beta |
20 B | 0 B | 20 B | 0 B | 0 B |
Chunks:
| Entry | Chunk | Load | Size (gz) |
|---|---|---|---|
./js |
index.js |
initial | 4.2 KB |
./js |
chunk |
initial | 120 B |
./js |
apache-arrow |
lazy | 49 KB |
./js/beta |
beta.js |
initial | 20 B |
./react |
index.js |
initial | 427 KB |
./react |
tslib |
initial | 2.1 KB |
./react |
apache-arrow |
lazy | 49 KB |
./react/beta |
beta.js |
initial | 20 B |
🤖 AppKit PR bot🔬 Run evalsStart an eval for this PR from the evals-monitor app: Go to Evals Monitor → 📦 Try this PR's app templateScaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh run download 30350002228 -R databricks/appkit -n appkit-template-0.48.0-pr.1400f5f-evgenii-metric-config-empty-definitions-493 -D appkit-pr-493 \
&& unzip -o "appkit-pr-493/appkit-template-0.48.0-pr.1400f5f-evgenii-metric-config-empty-definitions-493.zip" -d "appkit-pr-493" \
&& databricks apps init --template "appkit-pr-493"The template pins |
There was a problem hiding this comment.
@keugenek Are you sure this is correct fix?
The templating syntax should be only used for unrendered template, and the databricks apps init command renders it so that there's no longer such syntax 🤔. t
The type generator shouldn't see {{ ... }} go templating at all after the template is rendered. What I mean is that the descrinbed "Running typegen against the raw template" isn't a valid case and we don't support it - we should use the template (PR one, or whatever one) only after running databricks apps init --template {path} with proper flags.
You can even see the automatic comment how to use the PR template artifact:
Does it make sense?
|
Closing this — @pkosiec is right that the type generator shouldn't ever see un-rendered The real bug was on the consumer side: the App Builder eval harness was raw-copying the template ( |
Summary
readMetricConfigthrew a fatalFailed to parse definitions.jsonwheneverconfig/metric-views/definitions.jsonwas empty or still held its un-rendered Go-template guard.The template ships that file wrapped in
{{if .plugins.analytics}}:So two entirely normal situations produced invalid JSON:
npm installpostinstall→appkit generate-typeswarmup, beforeappkit setuprenders anything) → the literal{{...}}is still present.Both are "no metric views defined" — an additive, non-error state the function already documents (
Returns null if the file does not exist ... apps without definitions.json must not be penalized). ButJSON.parse("")/JSON.parse("{{...")threw, abortingappkit generate-typesand thus failingnpm installfor any analytics-off app and any tool that warms the raw template.Fix
Treat empty / whitespace-only / un-rendered (
{{-prefixed) content the same as an absent file —return null. A non-empty, rendered file with genuinely malformed JSON still throws loudly, so real misconfiguration is unaffected.How I found it
Discovered while running the Databricks app-evals harness against the
latestAppKit template (template-v0.48.0): the eval cluster's template npm-warmup and the agent'sappkit setupboth died withFATAL config/metric-views/definitions.json: Failed to parse definitions.json ... Expected property name or '}' in JSON.Testing
Added
mv-registrytests for the empty, whitespace-only, and un-rendered cases (each expectsnull); the existing "throws on malformed JSON" test still guards that genuine bad JSON errors. Verified the branch logic against all six cases (absent / empty / whitespace / unrendered / valid / malformed).This pull request and its description were written by Isaac.