Skip to content

Every failed instrument build reports an extra "Cannot read properties of undefined (reading 'inputs')" error from the bundler plugin #1800

Open

Description

@joshunrau

Every failed instrument build reports one error too many. The extra error is the bundler crashing on itself: Cannot read properties of undefined (reading 'inputs'). The plugin's onEnd hook reads result.metafile!.inputs unconditionally, but esbuild does not produce a metafile when the build has errors. So the hook throws a TypeError, and esbuild appends it to BuildFailure.errors as a second error attributed to instrument-bundler-plugin. Any author with a syntax error or a missing file then sees "Build failed with 2 errors" and an internal TypeError alongside their real mistake. This appears in the playground's error fallback (its "Cause" section shows the esbuild message), in serve-instrument's log, and in the API's instrument repo import log.

Where

packages/instrument-bundler/src/plugin.ts:86-95:

      build.onEnd((result) => {
        result.legacyScripts = [];
        Object.keys(result.metafile!.inputs).forEach((path) => {
          const script = legacyScripts.get(path.replace('bundle:', ''));
          // ...
        });
      });

Reproduce

  1. bundle({ inputs: [{ name: 'index.ts', content: "export default { kind: 'FORM', ;" }] }).

Actual: the thrown error's cause.errors holds two messages: Expected identifier but found ";" and Cannot read properties of undefined (reading 'inputs') from instrument-bundler-plugin (verified on main). A missing import (import x from './nope.ts') also gets the same spurious second error.
Expected: cause.errors holds only the author's error.

Tests

packages/instrument-bundler/src/__tests__/build.test.ts: it('should report only the source error when compilation fails, so authors do not see an internal TypeError'). Run the real esbuild on a source with a syntax error and assert cause.errors has length 1.

e2e, in testing/src/specs/playground.spec.ts: introduce a syntax error in the editor and assert the error fallback does not contain reading 'inputs'.

Suggested fix

Return early from the onEnd callback when the build failed (if (!result.metafile) return;, or check result.errors.length).

Activity

  1. added
    BugType: existing behavior is wrong
    Priority: LowNice to have, cosmetic or speculative
    Difficulty: LowIsolated change, about 2 hours or less
    Area: InstrumentsInstrument authoring API, bundling, runtime, rendering, measures and the built-in library
    Good First IssueWell-scoped, low-risk and self-contained; a good entry point for a new contributor
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: InstrumentsInstrument authoring API, bundling, runtime, rendering, measures and the built-in libraryBugType: existing behavior is wrongDifficulty: LowIsolated change, about 2 hours or lessGood First IssueWell-scoped, low-risk and self-contained; a good entry point for a new contributorPriority: LowNice to have, cosmetic or speculative

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions