{"record":{"id":"988a518708da8c24","repo":"caddyserver/caddy","slug":"position-d-v","errorCode":null,"errorMessage":"position %d: %v","messagePattern":"position (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context.go","lineNumber":233,"sourceCode":"\t\t\tif inlineModuleKey == \"\" {\n\t\t\t\tpanic(\"unable to determine module name without inline_key when type is not a ModuleMap\")\n\t\t\t}\n\t\t\tval, err := ctx.loadModuleInline(inlineModuleKey, moduleNamespace, val.Interface().(json.RawMessage))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tresult = val\n\t\t} else if isJSONRawMessage(typ.Elem()) {\n\t\t\t// val is `[]json.RawMessage`\n\n\t\t\tif inlineModuleKey == \"\" {\n\t\t\t\tpanic(\"unable to determine module name without inline_key because type is not a ModuleMap\")\n\t\t\t}\n\t\t\tvar all []any\n\t\t\tfor i := 0; i < val.Len(); i++ {\n\t\t\t\tval, err := ctx.loadModuleInline(inlineModuleKey, moduleNamespace, val.Index(i).Interface().(json.RawMessage))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"position %d: %v\", i, err)\n\t\t\t\t}\n\t\t\t\tall = append(all, val)\n\t\t\t}\n\t\t\tresult = all\n\t\t} else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {\n\t\t\t// val is `[][]json.RawMessage`\n\n\t\t\tif inlineModuleKey == \"\" {\n\t\t\t\tpanic(\"unable to determine module name without inline_key because type is not a ModuleMap\")\n\t\t\t}\n\t\t\tvar all [][]any\n\t\t\tfor i := 0; i < val.Len(); i++ {\n\t\t\t\tinnerVal := val.Index(i)\n\t\t\t\tvar allInner []any\n\t\t\t\tfor j := 0; j < innerVal.Len(); j++ {\n\t\t\t\t\tinnerInnerVal, err := ctx.loadModuleInline(inlineModuleKey, moduleNamespace, innerVal.Index(j).Interface().(json.RawMessage))\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn nil, fmt.Errorf(\"position %d: %v\", j, err)","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/context.go#L215-L251","documentation":"Caddy's module loader (Context.LoadModule) uses reflection to provision struct fields typed as []json.RawMessage, where each slice element is an inline module (module name embedded as a key in the JSON object). When loading the element at index i fails, this error decorates the underlying failure with the slice position. The underlying cause is almost always an unknown module name, a malformed inline module object, or a provisioning/decoding failure inside the nested module.","triggerScenarios":"A module struct has a field like []json.RawMessage with caddy:\"module=...\" tags; the JSON config supplies an array of inline module objects; ctx.loadModuleInline fails for element i (e.g. missing inline module-name key, unregistered module name, or StrictUnmarshalJSON rejecting a field), and LoadModule returns fmt.Errorf(\"position %d: %v\", i, err).","commonSituations":"Typing a wrong handler/module name in a JSON array of matchers or handlers; forgetting the inline key (e.g. \"handler\" or \"matcher\") in one element of the array; using a plugin module in JSON config without building a Caddy binary that imports the plugin; strict decoding rejecting an unknown field in one element.","solutions":["Read the %v part of the message: it names the real cause (e.g. 'unknown module: http.handlers.fwo' or 'decoding module config: ...')","Check the JSON array element at the reported 0-based position; verify its inline module-name key (handler/matcher/listener/etc.) is present and spelled correctly","Verify the module is registered in this build: run `caddy list-modules` and confirm the module ID appears (add the plugin via xcaddy build or an import if missing)","Remove unrecognized fields from that element or fix field types, since Caddy uses strict JSON decoding (unknown keys are rejected)"],"exampleFix":"// before (JSON config)\n\"routes\": [ { \"handle\": [ { \"handlr\": \"static_response\", \"body\": \"hi\" } ] } ]\n// after\n\"routes\": [ { \"handle\": [ { \"handler\": \"static_response\", \"body\": \"hi\" } ] } ]","handlingStrategy":"validation","validationCode":"// Before applying config: adapt + validate so positions/inline keys are checked upfront\ncmd := exec.Command(\"caddy\", \"validate\", \"--config\", \"Caddyfile\", \"--adapter\", \"caddyfile\")\nif out, err := cmd.CombinedOutput(); err != nil {\n    log.Fatalf(\"config invalid: %v\\n%s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"// In Go code embedding Caddy\nif _, err := ctx.LoadModule(field, raw); err != nil {\n    return fmt.Errorf(\"loading inline module slice: %w\", err) // 'position N:' names the element\n}","preventionTips":["Validate configs with `caddy validate` before deploying or reloading","Generate JSON via `caddy adapt` instead of hand-writing inline module objects","Verify every module ID exists with `caddy list-modules` before referencing it"],"tags":["caddy","module-system","config","json","reflection"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}