How to handle unknown errors from a model

A how to guide to display a user message when unknown model errors occur.

Introduction

When a model is computed as part of your solution it might fail for unknown reasons. Such reasons might include:

  • A problem with the user’s access rights
  • A hickup in the user’s internet connection
  • An execution timeout or unhandled execution error

Regardless of the cause, it is a good idea to help the user understand what is going on. This guide focusses on setting up a so called snackbar notification message for such events. It is advised to always include this for your models.

Prerequisites

1. Setup your solution with model and controls

Let’s start with a solution that contains a model with a single input named value which is controlled by a corresponding text input in a control panel

kind: Frame
contents:
  model:
    kind: Model
    modelFile: model.gh
    subscribe:
      - kind: ControlPanel
        frame: main
        source: controls
  controls:
    kind: ControlPanel
    controls:
      value:
        kind: TextInput
        placeholder: Please provide a value

2. Add the snack bar

When this model fails we would like to inform the user of this. To do this we can add a SnackBar block and subscribe it to the model error status:

message:
  kind: SnackBar
  subscribe:
    - kind: Model
      frame: main
      source: model
      onStatus: error
      message:
        kind: StaticMessage
        message: The model failed to solve

Of course the message displayed may be customized to your needs to better inform the user.

In the event of a model error the user will see the following message:

Configuration

See the SnackBar block documentation for more information.