wailsapp/wails · error

Unknown menu type: %v

Error message

Unknown menu type: %v

What it means

This is the GTK3-legacy twin of the GTK4 factory panic: newMenuItemImpl (v3/pkg/application/menuitem_linux_gtk3.go:118, built only with -tags gtk3) handles only text, checkbox and submenu values of the menuItemType enum (menuitem.go:11-16); separator, radio and anything else fall into default: and panic. menu_linux_gtk3.go routes checkbox/radio to their own factories, so in practice a separator item or a hand-built MenuItem with a bad itemType reaching this generic factory triggers the crash.

Source

Thrown at v3/pkg/application/menuitem_linux_gtk3.go:118

func newMenuItemImpl(item *MenuItem) *linuxMenuItem {
	result := &linuxMenuItem{
		menuItem: item,
	}
	switch item.itemType {
	case text:
		result.native = menuItemNew(item.label, item.bitmap)

	case checkbox:
		result.native = menuCheckItemNew(item.label, item.bitmap)
		result.setChecked(item.checked)
		if item.accelerator != nil {
			result.setAccelerator(item.accelerator)
		}
	case submenu:
		result.native = menuItemNew(item.label, item.bitmap)

	default:
		panic(fmt.Sprintf("Unknown menu type: %v", item.itemType))
	}
	result.setDisabled(result.menuItem.disabled)
	return result
}

func newRadioItemImpl(item *MenuItem, group GSListPointer) *linuxMenuItem {
	result := &linuxMenuItem{
		menuItem: item,
		native:   menuRadioItemNew(group, item.label),
	}
	result.setChecked(item.checked)
	result.setDisabled(result.menuItem.disabled)
	return result
}

func newSpeechMenu() *MenuItem {
	speechMenu := NewMenu()
	speechMenu.Add("Start Speaking").

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Ensure separator items are filtered or handled before newMenuItemImpl is called (see processMenu in menu_linux_gtk3.go) — skip separators or map them to gtk_separator_menu_item_new().
  2. If you own the factory, add a separator case to the switch instead of letting it hit default.
  3. Create menu items only through NewMenuItem/NewCheckMenuItem/NewRadioMenuItem/NewSeparator so itemType is always valid.
  4. Migrate the app to the default GTK4 stack (drop -tags gtk3) — the legacy path is scheduled for removal in v3.1 and receives less testing.

Example fix

// before (menuitem_linux_gtk3.go)
switch item.itemType {
case text:
	result.native = menuItemNew(item.label, item.bitmap)
case checkbox:
	result.native = menuCheckItemNew(item.label, item.bitmap)
	...
case submenu:
	result.native = menuItemNew(item.label, item.bitmap)
default:
	panic(fmt.Sprintf("Unknown menu type: %v", item.itemType))
}

// after
switch item.itemType {
case text, submenu:
	result.native = menuItemNew(item.label, item.bitmap)
case checkbox:
	result.native = menuCheckItemNew(item.label, item.bitmap)
case separator:
	result.native = menuItemSeparatorNew()
default:
	panic(fmt.Sprintf("Unknown menu type: %v", item.itemType))
}
Defensive patterns

Strategy: validation

Validate before calling

// Before attaching menus in a -tags gtk3 build, ensure no item
// reaches the generic factory with an unsupported type.
// Practical guard: build items only via public constructors and
// verify separators are supported in your Wails version.
if runtime.GOOS == "linux" && usingGtk3Build() {
	// skip AddSeparator() unless verified, or test on the default GTK4 stack
}

Type guard

// Narrowing over menuItemType values (menuitem.go:11-16)
func isGenericFactoryType(t int) bool {
	// GTK3 generic factory: text(0), checkbox(2), submenu(4)
	return t == 0 || t == 2 || t == 4
}

Try / catch

defer func() {
	if r := recover(); r != nil {
		log.Printf("gtk3 menu build failed: %v", r)
	}
}()
menu := app.NewMenu()

Prevention

When it happens

Trigger: Building with -tags gtk3 (the legacy Linux stack retained for one v3 cycle) and adding separator items that get dispatched as normal items; constructing MenuItem values with out-of-range itemType; calling newMenuItemImpl directly without switching on item.itemType first.

Common situations: Apps pinned to GTK3/WebKit2GTK 4.1 during the v3 migration window (GTK4 became default per IMPLEMENTATION.md Decision 1.1); CI matrices that still build the gtk3 tag; code shared between GTK3 and GTK4 paths drifting apart.

Related errors


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/d908e9f9c7efa766. Report an issue: GitHub.