vegaprotocol / vegawallet-desktop

Desktop application for Vega Protocol's wallet
MIT License
15 stars 12 forks source link

Improve error mapping when receiving error interaction (generic) #543

Closed ValentinTrinque closed 1 year ago

ValentinTrinque commented 1 year ago

As a team We want to improve the way we report errors to the user and a way to report errors So that errors are more meaningful and we provide ways the user can get out of the situation

Initially we will do this at the generic level and then later we will find a way to do this at a more specific level for all the different errors (or at least the most common ones)

Tasks

Pattern for showing errors

Image

Design (errors in context of a transaction and separate from transactions)

https://www.figma.com/file/eMWtbGPxPHfnVSRsxF8M99/Desktop-Wallet?node-id=2608-3545&t=4eB9HKZRWkVF77nT-0

Error Categories + generic messaging

Application error

User error

Network error

Backend error

Internal error

Server error

Background / Details

In the core we have an error category with a description (broad) and a message (specific) per individual error

 case 'Application error': {
      return {
        title: type,
        description: 'The application prevented the request to proceed.',
      }
    }
    case 'Internal error': {
      return {
        title: type,
        description: 'An internal error occurred and could not be recovered. The request has been cancelled.',
      }
    }
    case 'Network error': {
      return {
        title: type,
        description: 'We couldn\'t fulfill your request due to network issues. Make sure your connection to the nodes is stable, and give it another go.',
      }
    }
    case 'User error': {
      return {
        title: 'Error',
        description: '', // No description. This type of error is handled in a specific way.
      }
    }

Sample of errors:

ApplicationError, ErrNoWalletToConnectTo
ApplicationError, ErrRequestInterrupted
ApplicationError, fmt.Errorf("could not compute the proof-of-work: %w", err)
ApplicationError, fmt.Errorf("could not send transaction: %w", err)
InternalError, fmt.Errorf("could not compute the proof-of-work: %w", err)
InternalError, fmt.Errorf("could not list the available wallets: %w", err)
InternalError, fmt.Errorf("could not marshal input data: %w", err)
InternalError, fmt.Errorf("could not retrieve the wallet associated to the connection: %w", err)
InternalError, fmt.Errorf("could not retrieve the wallet: %w", err)
InternalError, fmt.Errorf("could not sign the transaction: %w", err)
InternalError, fmt.Errorf("could not unlock the wallet: %w", err)
InternalError, fmt.Errorf("could not verify the wallet existence: %w", err)
InternalError, fmt.Errorf("could not verify whether the wallet is already unlock or not: %w", err)
InternalError, fmt.Errorf("requesting the transaction review failed: %w", err)
InternalError, fmt.Errorf("requesting the wallet passphrase failed: %w", err)
InternalError, fmt.Errorf("requesting the wallet selection failed: %w", err)
InternalError, fmt.Errorf("reviewing the wallet connection failed: %w", err)
NetworkError, ErrCouldNotGetChainIDFromNode
NetworkError, ErrCouldNotGetLastBlockInformation
NetworkError, fmt.Errorf("could not find a healthy node: %w", err)
NetworkError, fmt.Errorf("could not get the latest block information from the node: %w", err)
UserError, ErrWalletDoesNotExistUserError
UserError, wallet.ErrWrongPassphrase