PageSourceSearch

https://www.openpolicyagent.org/assets/js/f74f30c2.b61bdec4.js

js openpolicyagent.org collected 2026-09-24 08:29:38 UTC 5,316 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkopa_website=self.webpackChunkopa_website||[]).push([[17526],{28453:(e,r,n)=>{n.d(r,{R:()=>s,x:()=>a});var t=n(96540);const o={},i=t.createContext(o);function s(e){const r=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:s(e.components),t.createElement(i.Provider,{value:r},e.children)}},83181:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>s,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"errors/rego-type-error/function-has-arity-got-argument","title":"rego_type_error: function {name} has arity n, got m argument(s)","description":"Arity is a term used to describe the number of arguments a function takes.","source":"@site/docs/errors/rego-type-error/function-has-arity-got-argument.md","sourceDirName":"errors/rego-type-error","slug":"/errors/rego-type-error/function-has-arity-got-argument","permalink":"/docs/errors/rego-type-error/function-has-arity-got-argument","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"sidebar_label":"function name has arity n, got m argument(s)","image":"/img/opa-errors.png"},"sidebar":"docsSidebar","previous":{"title":"conflicting rules {name} found","permalink":"/docs/errors/rego-type-error/conflicting-rules-name-found"},"next":{"title":"match error","permalink":"/docs/errors/rego-type-error/match-error"}}');var o=n(74848),i=n(28453);const s={sidebar_label:"function name has arity n, got m argument(s)",image:"/img/opa-errors.png"},a="rego_type_error: function {name} has arity n, got m argument(s)",c={},d=[{value:"Examples",id:"examples",level:2},{value:"How To Fix It",id:"how-to-fix-it",level:2}];function l(e){const r={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",header:"header",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(r.header,{children:(0,o.jsxs)(r.h1,{id:"rego_type_error-function-name-has-arity-n-got-m-arguments",children:[(0,o.jsx)(r.code,{children:"rego_type_error"}),": function ",(0,o.jsx)(r.code,{children:"{name}"})," has arity n, got m argument(s)"]})}),"\n",(0,o.jsxs)(r.p,{children:[(0,o.jsx)(r.a,{href:"https://en.wikipedia.org/wiki/Arity",children:"Arity"})," is a term used to describe the number of arguments a function takes.\nThis error happens when a user-defined function is called with an unexpected number of arguments - the wrong ",(0,o.jsx)(r.em,{children:"arity"}),"."]}),"\n",(0,o.jsx)(r.admonition,{type:"note",children:(0,o.jsxs)(r.p,{children:["This message is only shown for user defined functions, not for Rego's built-in functions. For errors\ncontaining ",(0,o.jsx)(r.code,{children:"arity mismatch"})," see ",(0,o.jsx)(r.a,{href:"./arity-mismatch",children:"this section"}),"."]})}),"\n",(0,o.jsxs)(r.table,{children:[(0,o.jsx)(r.thead,{children:(0,o.jsxs)(r.tr,{children:[(0,o.jsx)(r.th,{children:"Stage"}),(0,o.jsx)(r.th,{children:"Category"}),(0,o.jsx)(r.th,{children:"Message"})]})}),(0,o.jsx)(r.tbody,{children:(0,o.jsxs)(r.tr,{children:[(0,o.jsx)(r.td,{children:(0,o.jsx)(r.code,{children:"compilation"})}),(0,o.jsx)(r.td,{children:(0,o.jsx)(r.code,{children:"rego_type_error"})}),(0,o.jsxs)(r.td,{children:[(0,o.jsx)(r.code,{children:"{name}"})," has arity n, got m argument(s)`"]})]})})]}),"\n",(0,o.jsx)(r.h2,{id:"examples",children:"Examples"}),"\n",(0,o.jsxs)(r.p,{children:["In the following example, the user-defined function ",(0,o.jsx)(r.code,{children:"is_authorized"})," function is called with one argument,\nbut it takes two:"]}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-rego",children:"package policy\n\nimport future.keywords.if\nimport future.keywords.in\n\ndefault is_authorized(_, _) := false\n\nis_authorized(user_id, resource) if {\n    # implementation details\n}\n\ndefault allow := false\n\nallow := is_authorized(input)\n"})}),"\n",(0,o.jsx)(r.p,{children:"When compiled, this will result in the following error:"}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-txt",children:"1 error occurred: policy.rego:16: rego_type_error: function data.policy.is_authorized has arity 2, got 1 argument\n"})}),"\n",(0,o.jsx)(r.h2,{id:"how-to-fix-it",children:"How To Fix It"}),"\n",(0,o.jsxs)(r.p,{children:["In order to find the function that's being called with the wrong arity, you first need to find the line number\nin the error message - ",(0,o.jsx)(r.code,{children:"16"})," in the example above. On that line, update the function call to pass the\ncorrect number of arguments. The example above might be fixed like so:"]}),"\n",(0,o.jsx)(r.pre,{children:(0,o.jsx)(r.code,{className:"language-rego",children:"package policy\n\nimport future.keywords.if\nimport future.keywords.in\n\ndefault is_authorized(_, _) := false\n\nis_authorized(user_id, resource) if {\n    # implementation details\n}\n\ndefault allow := false\n\nallow := is_authorized(input.user_id, input.resource) # pass two arguments\n"})})]})}function h(e={}){const{wrapper:r}={...(0,i.R)(),...e.components};return r?(0,o.jsx)(r,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.