{"record":{"id":"22b4a2788b8c7158","repo":"clojure/clojure","slug":"too-many-arguments-to-def","errorCode":null,"errorMessage":"Too many arguments to def","messagePattern":"Too many arguments to def","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/jvm/clojure/lang/Compiler.java","lineNumber":535,"sourceCode":"\n\tpublic boolean hasJavaClass(){\n\t\treturn true;\n\t}\n\n\tpublic Class getJavaClass(){\n\t\treturn Var.class;\n\t}\n\n\tstatic class Parser implements IParser{\n\t\tpublic Expr parse(C context, Object form) {\n\t\t\t//(def x) or (def x initexpr) or (def x \"docstring\" initexpr)\n\t\t\tString docstring = null;\n\t\t\tif(RT.count(form) == 4 && (RT.third(form) instanceof String)) {\n\t\t\t\tdocstring = (String) RT.third(form);\n\t\t\t\tform = RT.list(RT.first(form), RT.second(form), RT.fourth(form));\n\t\t\t}\n\t\t\tif(RT.count(form) > 3)\n\t\t\t\tthrow Util.runtimeException(\"Too many arguments to def\");\n\t\t\telse if(RT.count(form) < 2)\n\t\t\t\tthrow Util.runtimeException(\"Too few arguments to def\");\n\t\t\telse if(!(RT.second(form) instanceof Symbol))\n\t\t\t\t\tthrow Util.runtimeException(\"First argument to def must be a Symbol\");\n\t\t\tSymbol sym = (Symbol) RT.second(form);\n\t\t\tVar v = lookupVar(sym, true);\n\t\t\tif(v == null)\n\t\t\t\tthrow Util.runtimeException(\"Can't refer to qualified var that doesn't exist\");\n\t\t\tif(!v.ns.equals(currentNS()))\n\t\t\t\t{\n\t\t\t\tif(sym.ns == null)\n\t\t\t\t\t{\n\t\t\t\t\tv = currentNS().intern(sym);\n\t\t\t\t\tregisterVar(v);\n\t\t\t\t\t}\n//\t\t\t\t\tthrow Util.runtimeException(\"Name conflict, can't def \" + sym + \" because namespace: \" + currentNS().name +\n//\t\t\t\t\t                    \" refers to:\" + v);\n\t\t\t\telse","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/clojure/clojure/blob/f3b143341d6efc6428b523b2eaa099a6cc99156e/src/jvm/clojure/lang/Compiler.java#L517-L553","documentation":"During macroexpansion of a def special form, the compiler accepts at most (def sym init) or (def sym \"docstring\" init). If the form still has more than 3 elements after the docstring case is peeled off, the def is malformed and the compiler throws instead of guessing which extra argument was intended.","triggerScenarios":"Evaluating a def form with extra elements, e.g. (def x 1 2), (def x 1 {:meta 1} 2), or a mis-built def generated by a macro that concatenates one argument too many.","commonSituations":"Hand-written defs with leftover arguments; macros that splice collections into def without flattening; copy-paste from languages allowing multiple bindings in one declaration; refactoring that left a stale argument in place.","solutions":["Remove the extra arguments so the form is (def name value) or (def name \"doc\" value).","If metadata was intended, attach it with ^meta reader syntax or (def ^{:k v} name value) instead of positional arguments.","Inspect the macro that emits the def and fix its expansion (macroexpand-1 the call)."],"exampleFix":"// before\n(def config \"app config\" {:a 1} :extra)\n// after\n(def ^{:doc \"app config\"} config {:a 1})","handlingStrategy":"validation","validationCode":"(when (> (count form) (if (string? (nth form 2 nil)) 4 3))\n  (throw (ex-info \"def form has too many arguments\" {:form form})))","typeGuard":null,"tryCatchPattern":"try {\n  (eval form)\n} catch (RuntimeException e) {\n  (when (.contains (.getMessage e) \"Too many arguments to def\")\n    (println \"Fix def form arity:\" form))\n}","preventionTips":["Keep def forms to (def name value) or (def name \"doc\" value).","Attach metadata with ^ reader syntax, not extra positional arguments.","Macroexpand generated defs before evaluating them."],"tags":["compiler","def","clojure","arity"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3b143341d6efc6428b523b2eaa099a6cc99156e","analyzedAt":"2026-09-09T12:04:58.961Z","contentChangedAt":"2026-09-09T12:04:58.961Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}