Skip to content
ricardoboss edited this page Sep 13, 2023 · 1 revision

Invalid Result Type Exception

Description

A function returned an unexpected result type. This can happen if a function was called without handling its result (hence a void result was expected), or when trying to save the result of a function that does not return anything:

Example:

function add = (number a, number b) {
	return a + b
}

add(1, 2)

or:

function printMessage = (string message) {
	print("msg: ", message)
}

string result = printMessage("Hello, World!")

Remediation

Ensure the function you are trying to call returns the type you are expecting.

Example:

  function add = (number a, number b) {
  	return a + b
  }

- add(1, 2)
+ number result = add(1, 2)

or alternatively, discard the result explicitly:

  function add = (number a, number b) {
  	return a + b
  }

- add(1, 2)
+ _ = add(1, 2)

When handling void functions, ensure you do not try to save their result:

  function printMessage = (string message) {
  	print("msg: ", message)
  }

- string result = printMessage("Hello, World!")
+ printMessage("Hello, World!")