wailsapp/wails · error

use ShowAndGetResults for open multiple files dialog

Error message

use ShowAndGetResults for open multiple files dialog

What it means

ShowAndGetResult() on the single-select file-open dialog panics if the dialog was created as a multi-select dialog (FOS_ALLOWMULTISELECT). The library deliberately panics because calling the wrong pairing is a programming error by the developer using the API, not a runtime condition.

Source

Thrown at v2/internal/go-common-file-dialog/cfd/iFileOpenDialog.go:53

	}
}

func (fileOpenDialog *iFileOpenDialog) Show() error {
	return fileOpenDialog.vtbl.show(unsafe.Pointer(fileOpenDialog), fileOpenDialog.parentWindowHandle)
}

func (fileOpenDialog *iFileOpenDialog) SetParentWindowHandle(hwnd uintptr) {
	fileOpenDialog.parentWindowHandle = hwnd
}

func (fileOpenDialog *iFileOpenDialog) ShowAndGetResult() (string, error) {
	isMultiselect, err := fileOpenDialog.isMultiselect()
	if err != nil {
		return "", err
	}
	if isMultiselect {
		// We should panic as this error is caused by the developer using the library
		panic("use ShowAndGetResults for open multiple files dialog")
	}
	if err := fileOpenDialog.Show(); err != nil {
		return "", err
	}
	return fileOpenDialog.GetResult()
}

func (fileOpenDialog *iFileOpenDialog) ShowAndGetResults() ([]string, error) {
	isMultiselect, err := fileOpenDialog.isMultiselect()
	if err != nil {
		return nil, err
	}
	if !isMultiselect {
		// We should panic as this error is caused by the developer using the library
		panic("use ShowAndGetResult for open single file dialog")
	}
	if err := fileOpenDialog.Show(); err != nil {
		return nil, err

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Call ShowAndGetResults() (plural) on multi-select dialogs
  2. If single-file selection is intended, create the dialog without the multiselect option

Example fix

// before
dialog, _ := cfd.NewDialog(cfd.ForceFilePicker) // multiselect set elsewhere
result, err := dialog.ShowAndGetResult() // panics

// after
results, err := dialog.ShowAndGetResults() // returns []string
Defensive patterns

Strategy: type-guard

Validate before calling

// know your dialog mode at creation time and store it
multi := false // set true only when multiselect was configured
if multi { paths, err := dialog.ShowAndGetResults() } else { path, err := dialog.ShowAndGetResult() }

Type guard

// use the interface the library gives you: MultiFileDialog only exposes the plural APIs
func openFiles(d cfd.MultiFileDialog) ([]string, error) {
    return d.ShowAndGetResults()
}

Prevention

When it happens

Trigger: Creating the dialog via the multi-select constructor/path and then calling ShowAndGetResult() instead of ShowAndGetResults().

Common situations: Copy-pasting single-file dialog sample code onto a multi-select dialog, or refactoring a dialog from single to multi selection without updating the call site.

Related errors


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