Skip to content

Replace broad custom assembly bind exception catch with typed failure path #186

@jonathanvdc

Description

@jonathanvdc

Problem

Binder.BindOperation currently catches Exception around definition.AssemblyFormat.Bind(syntax, this) so failures in generated custom assembly binding become recoverable AssemblyDiagnostics plus an UninterpretedOperation. This restored the desired module-level recovery behavior for malformed custom bodies, but the catch-all is too broad.

The broad catch can accidentally hide programmer bugs in generated or handwritten assembly formats, while still being necessary today to prevent expected shape failures from aborting an entire module bind.

Current motivation

Revived dialect tests now exercise custom-body binding failure cases:

  • wrong generated body syntax type
  • wrong result count / missing expected result token

Before the recovery wrapper, these escaped as exceptions such as InvalidOperationException or ArgumentOutOfRangeException. Generic operation binding already reports comparable structural problems as assembly diagnostics and continues binding, so custom assembly should have an equivalent but cleaner failure path.

Desired direction

Find and implement a typed alternative to catching all exceptions. Possible approaches:

  • introduce a dedicated AssemblyFormatBindingException (or result type) for expected custom assembly binding failures;
  • make generated bind code explicitly validate body type, result count, operand count, and region count before indexing;
  • return a bind result/diagnostic from IOperationAssemblyFormat.Bind instead of throwing for expected failures;
  • keep truly unexpected exceptions visible so generator/runtime bugs are not silently downgraded to diagnostics.

Acceptance criteria

  • malformed custom assembly bodies produce AssemblyDiagnostics and UninterpretedOperations without aborting module binding;
  • generated custom bind code does not rely on ArgumentOutOfRangeException/InvalidOperationException for ordinary shape validation;
  • unexpected implementation bugs are not swallowed by a blanket catch (Exception);
  • the currently revived MiniArith custom-body failure tests remain active and passing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions