Skip to content

on.Click(...) panic message lumps three failure modes together #36

Description

@joaomdsg

Severity: medium

Summary

When the argument to on.Click (or any on.*) isn't a bound method value, the panic text is

on: click requires a bound method value (e.g. on.Click(c.Inc)); got a closure, top-level function, or nil

The framework already has the reflect.Value of the failing argument and can distinguish closure / top-level / nil.

Where

  • on/on.go:161
  • on/on.go:232

Why it matters

UX nit, but this is the most common authoring mistake for the on package and the message is one of the most-read. Telling the dev exactly which of the three they did wrong saves a round of squinting.

Suggested fix

Switch on the value's kind / nil-ness and emit the specific case:

case fn == nil:           → "got nil"
case top-level function:  → "got a top-level function — Via needs a method bound to a composition instance"
default (closure):        → "got a closure — Via needs a method directly, not wrapped"

runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name() exposes the underlying function name and lets you detect closures by the .func1 suffix convention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions