wailsapp/wails · error

use GetResult for open single file dialog

Error message

use GetResult for open single file dialog

What it means

GetResults() (plural) panics when called on a single-select dialog. The library comment notes this method should only be reachable for multi-select dialogs since the single-select Dialog interface does not expose it; hitting the panic means the wrong interface/method pairing was used.

Source

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

func (fileOpenDialog *iFileOpenDialog) SetFileFilters(filter []FileFilter) error {
	return fileOpenDialog.vtbl.setFileTypes(unsafe.Pointer(fileOpenDialog), filter)
}

func (fileOpenDialog *iFileOpenDialog) SetRole(role string) error {
	return fileOpenDialog.vtbl.setClientGuid(unsafe.Pointer(fileOpenDialog), StringToUUID(role))
}

// This should only be callable when the user asks for a multi select because
// otherwise they will be given the Dialog interface which does not expose this function.
func (fileOpenDialog *iFileOpenDialog) GetResults() ([]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 GetResult for open single file dialog")
	}
	return fileOpenDialog.vtbl.getResultsStrings(unsafe.Pointer(fileOpenDialog))
}

func (fileOpenDialog *iFileOpenDialog) SetDefaultExtension(defaultExtension string) error {
	return fileOpenDialog.vtbl.setDefaultExtension(unsafe.Pointer(fileOpenDialog), defaultExtension)
}

func (fileOpenDialog *iFileOpenDialog) SetFileName(initialFileName string) error {
	return fileOpenDialog.vtbl.setFileName(unsafe.Pointer(fileOpenDialog), initialFileName)
}

func (fileOpenDialog *iFileOpenDialog) SetSelectedFileFilterIndex(index uint) error {
	return fileOpenDialog.vtbl.setSelectedFileFilterIndex(unsafe.Pointer(fileOpenDialog), index)
}

func (fileOpenDialog *iFileOpenDialog) setPickFolders(pickFolders bool) error {
	const FosPickfolders = 0x20

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Use GetResult() (singular) on single-select dialogs
  2. Type-hint variables as cfd.Dialog or cfd.MultiFileDialog so only the correct methods are visible

Example fix

// before
var d cfd.MultiFileDialog = singleSelectDialog // or direct concrete use
paths, _ := d.GetResults() // panics

// after
var d cfd.Dialog = singleSelectDialog
path, _ := d.ShowAndGetResult()
Defensive patterns

Strategy: type-guard

Validate before calling

// single-select: singular accessor only
path, err := dialog.GetResult()

Type guard

func resultOf(d cfd.Dialog) (string, error) {
    // Dialog interface hides GetResults; misuse becomes a compile error
    return d.GetResult()
}

Prevention

When it happens

Trigger: Calling GetResults() on a dialog created without the multiselect option, usually via a type-asserted or directly-constructed iFileOpenDialog.

Common situations: Writing generic helper code that always calls GetResults() regardless of dialog kind, or holding the concrete type instead of the Dialog/MultiFileDialog interface.

Related errors


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