wailsapp / wailsapp/wails

Improve Error Handling

Open
#3,301 10 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement Linux MacOS P2 v3 Windows
Dominant language
Go
Stars
36.3k
Forks
1.9k
Avg merge
2d 11h
Merged PRs (30d)
33

Description

Is your feature request related to a problem? Please describe.

Yes. Currently, in both the v2 and v3 versions of the API there is little to no error handling. The result is either panics or calls to log.Fatal. It's wilding frustrating to have a 3rd party library crashing my application.

In idiomatic Go we return an error if there is a problem. In the Wails API however, there are very little errors returned. Instead, when there is a problem the application either crashes with a panic or a call to log.Fatal. This makes applications nearly impossible to test and require the end user to wrap significant portions of the API to prevent these situations.

Describe the solution you'd like

I suggest idiomatic go error handling be implemented and nil checks are implemented.

Consider the following code snippet from the v3 API.

func (a *App) Capabilities() capabilities.Capabilities {
	return a.capabilities
}

If a is nil, then this code will panic and crash my applications and tests.

Consider the same code, but with a nil check and error handling.

func (a *App) Capabilities() ( capabilities.Capabilities, error ) {
	if a == nil {
		return capabilities.Capabilities{}, fmt.Errorf("app is nil")
	}
	return a.capabilities
}

Now, my application, or tests, will no longer panic and crash, but will return an error I can check and handle.

Describe alternatives you've considered

As an alternative to this I've had to wrap the entire v2 API in safe, idiomatic code, https://github.com/markbates/wailsx. This is, obviously, not a long term solution, especially with v3 in alpha. I do hope, however, that it might prove to be a guideline for further API discussion.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the v2 and v3 API entry points, including App.Capabilities, and compare their behavior with the wailsx wrapper linked in the issue. Determine the intended error-handling scope and API changes first; done should mean failures no longer panic or call log.Fatal and callers can check returned errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.