karatelabs/karate · error · IllegalArgumentException

registerReportAssets: assets is null

Error message

registerReportAssets: assets is null

What it means

Suite.registerReportAssets(ReportAssets, ClassLoader) throws this IllegalArgumentException when the ReportAssets spec is null. Report assets are static JS/CSS/image resources bundled into ext reports; a null spec cannot be validated or bound, so the Suite fails loud at boot rather than producing a broken report later.

Solutions

  1. Ensure a valid ReportAssets is constructed, e.g. ReportAssets.named("image").js("static/ext.js"), before calling
  2. Guard the call site: only invoke registerReportAssets when the assets object is non-null
  3. If assets come from config, fail early with a clear message when the configured spec cannot be built

Example fix

// before
ReportAssets assets = maybeBuildAssets();
suite.registerReportAssets(assets, getClass().getClassLoader());
// after
ReportAssets assets = maybeBuildAssets();
if (assets != null) {
    suite.registerReportAssets(assets, getClass().getClassLoader());
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (assets != null) suite.registerReportAssets(assets, classLoader);

Type guard

boolean hasAssets(ReportAssets a) { return a != null; }

Try / catch

try { suite.registerReportAssets(assets, cl); } catch (IllegalArgumentException e) { /* null assets: skip or fail boot with message */ }

Prevention

When it happens

Trigger: Calling suite.registerReportAssets(null, classLoader), or passing a variable/expression that evaluated to null (e.g. a builder method chain that returned null, or a map lookup miss).

Common situations: Conditional asset registration code like assets == something ? null : ...; a helper method returning null when no assets configured; refactoring removed the ReportAssets.named(...) construction while the call site remained.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/d868d6f8919bfce1. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/Suite.java:800

    public Object getGlobal(String name) {
        return globals.get(name);
    }

    /** Immutable view of all ext globals, in registration order. */
    public Map<String, Object> getGlobals() {
        return Collections.unmodifiableMap(globals);
    }

    /**
     * Register an ext's report-asset contribution. Called by an {@link Ext} from
     * {@link Ext#onBoot(Suite)} with a fluent {@link ReportAssets} spec, e.g.
     * {@code suite.registerReportAssets(ReportAssets.named("image").js("static/ext.js"), getClass().getClassLoader())}.
     * Validates the spec against the classloader (referenced resources must exist);
     * any failure throws and so fails the Suite loud at boot (see EXT.md § Report assets).
     */
    public void registerReportAssets(ReportAssets assets, ClassLoader classLoader) {
        if (assets == null) {
            throw new IllegalArgumentException("registerReportAssets: assets is null");
        }
        assets.validateAndBind(classLoader);
        reportAssets.put(assets.name(), assets);
    }

    /** Immutable view of all registered ext report-asset specs, in registration order. */
    public Map<String, ReportAssets> getReportAssets() {
        return Collections.unmodifiableMap(reportAssets);
    }

    /**
     * Contribute one KPI summary card to the summary-page hero (a key/value tile, e.g.
     * {@code {label:'Coverage', value:'53%', sub:'8/15 endpoints'}}). Called by an {@link Ext}
     * from {@link Ext#onShutdown()} (the values are post-run), which the run loop invokes before
     * the report listener writes the summary, so cards are inlined into the page. Optional keys
     * the renderer understands: {@code sub} (a second line), {@code href} (click-through), and
     * {@code status} ({@code ok}/{@code warn}/{@code fail}, for accent colour).
     */

View on GitHub (pinned to a22eb90246)