Skip to main content

rego_type_error: function {name} has arity n, got m argument(s)

Arity is a term used to describe the number of arguments a function takes. This error happens when a user-defined function is called with an unexpected number of arguments - the wrong arity.

note

This message is only shown for user defined functions, not for Rego's built-in functions. For errors containing arity mismatch see this section.

StageCategoryMessage
compilationrego_type_error{name} has arity n, got m argument(s)`

Examples

In the following example, the user-defined function is_authorized function is called with one argument, but it takes two:

package policy

import future.keywords.if
import future.keywords.in

default is_authorized(_, _) := false

is_authorized(user_id, resource) if {
# implementation details
}

default allow := false

allow := is_authorized(input)

When compiled, this will result in the following error:

1 error occurred: policy.rego:16: rego_type_error: function data.policy.is_authorized has arity 2, got 1 argument

How To Fix It

In order to find the function that's being called with the wrong arity, you first need to find the line number in the error message - 16 in the example above. On that line, we need to update the function call to pass the correct number of arguments. The example above might be fixed like so:

package policy

import future.keywords.if
import future.keywords.in

default is_authorized(_, _) := false

is_authorized(user_id, resource) if {
# implementation details
}

default allow := false

allow := is_authorized(input.user_id, input.resource) # pass two arguments

Community

For questions, discussions and announcements related to OPA, or Styra products, services and open source projects, please join the Styra Community on Slack.