Exceptions

The Runway Model SDK defines several custom exception types. All of these exceptions derive from the base RunwayError class, which itself derives from the standard Python Exception class. Each RunwayError contains error message and code properties, and a to_response() method that converts the exception to a Python dictionary, which can be returned as a JSON HTTP response.

try:
    do_something_with_runway()
except RunwayError as e:
    print(e.code, e.message)
    # 500 An unknown error has occurred
    print(e.to_response())
    # { "error": "An unknown error has occurred", "traceback": "..." }

Reference

exception runway.exceptions.RunwayError

Bases: Exception

A base error class that defines an HTTP error code, an error message, and can be formatted as an object to be returned as JSON in an HTTP request.

Variables
  • message – An error message, set to “An unknown error occurred.”

  • code – An HTTP error code, set to 500

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.MissingOptionError(name)

Bases: runway.exceptions.RunwayError

Thrown by the @runway.setup() decorator when a required option value has not been provided by the user.

Variables
  • message – An error message, set to “Missing option: {NAME_OF_MISSING_OPTION}”

  • code – An HTTP error code, set to 400

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.MissingInputError(name)

Bases: runway.exceptions.RunwayError

Thrown by the @runway.command() decorator when a required input value has not been provided by the user.

Variables
  • message – An error message, set to “Missing input: {NAME_OF_MISSING_OPTION}”

  • code – An HTTP error code, set to 400

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.InvalidArgumentError(name, message=None)

Bases: runway.exceptions.RunwayError

An error indicating that an argument is invalid. May be raised by @runway.setup() or @runway.command() decorated functions if they receive a bad input value.

Variables
  • message – An error message, set to “Invalid argument: {NAME_OF_MISSING_OPTION}”

  • code – An HTTP error code, set to 400

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.InferenceError(message)

Bases: runway.exceptions.RunwayError

An error thrown if there is an uncaught exception in a function decorated by @runway.command(). If this error is thrown, there is an exception in your code ;)

Variables
  • message – A repr() of original exception

  • code – An HTTP error code, set to 500

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.UnknownCommandError(name)

Bases: runway.exceptions.RunwayError

An error thrown if an HTTP request is made to an endpoint that doesn’t exist. E.g. http://localhost:9000/nothing_here.

Variables
  • message – An error message, set to “Unknown command: {COMMAND_NAME}”

  • code – An HTTP error code, set to 404

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.SetupError(message)

Bases: runway.exceptions.RunwayError

An error thrown if there is an uncaught exception in a function decorated by @runway.setup(). If this error is thrown, there is an exception in your code ;)

Variables
  • message – A repr() of original exception

  • code – An HTTP error code, set to 500

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict

exception runway.exceptions.MissingArgumentError(arg)

Bases: runway.exceptions.RunwayError

An error thrown when a required function argument is not provided.

Variables

message – An error message, set to “Missing argument:

{ARGUMENT_NAME}” :type message: string :ivar code: An HTTP error code, set to 500 :type code: number

get_traceback()

Return a list of lines containing the traceback of the exception currently being handled.

:return A list of lines of the exception traceback :rtype list

print_exception()

Print the exception message and traceback to stderr.

to_response()

Get information about the error formatted as a dictionary.

Returns

An object containing “error” and “traceback” keys.

Return type

dict