{"record":{"id":"6e4134da465bbff3","repo":"caddyserver/caddy","slug":"loading-module-s-v","errorCode":null,"errorMessage":"loading module '%s': %v","messagePattern":"loading module '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context.go","lineNumber":486,"sourceCode":"// a map[string]any, where one of the object keys is moduleNameKey\n// and the corresponding value is the module name (as a string) which can\n// be found in the given scope. In other words, the module name is declared\n// in-line with the module itself.\n//\n// This allows modules to be decoded into their concrete types and used when\n// their names cannot be the unique key in a map, such as when there are\n// multiple instances in the map or it appears in an array (where there are\n// no custom keys). In other words, the key containing the module name is\n// treated special/separate from all the other keys in the object.\nfunc (ctx Context) loadModuleInline(moduleNameKey, moduleScope string, raw json.RawMessage) (any, error) {\n\tmoduleName, raw, err := getModuleNameInline(moduleNameKey, raw)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tval, err := ctx.LoadModuleByID(moduleScope+\".\"+moduleName, raw)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"loading module '%s': %v\", moduleName, err)\n\t}\n\n\treturn val, nil\n}\n\n// App returns the configured app named name. If that app has\n// not yet been loaded and provisioned, it will be immediately\n// loaded and provisioned. If no app with that name is\n// configured, a new empty one will be instantiated instead.\n// (The app module must still be registered.) This must not be\n// called during the Provision/Validate phase to reference a\n// module's own host app (since the parent app module is still\n// in the process of being provisioned, it is not yet ready).\n//\n// We return any type instead of the App type because it is NOT\n// intended for the caller of this method to be the one to start\n// or stop App modules. The caller is expected to assert to the\n// concrete type.","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/context.go#L468-L504","documentation":"loadModuleInline extracts the module name from a JSON object using the expected inline key (module name embedded in the object, e.g. \"handler\": \"reverse_proxy\"), then loads it via LoadModuleByID with the scope prefixed. Any failure — bad inline key handling from getModuleNameInline, unknown module, decode/provision/validate errors — is wrapped as \"loading module '%s': %v\" naming the inline module name that was read.","triggerScenarios":"Calling ctx.loadModuleInline (internally from LoadModule on raw-message fields) where the object's inline key is missing (getModuleNameInline error), the name after scope-prefixing is not registered, or the module's config fails decoding/provisioning — each surfaces wrapped with the parsed module name.","commonSituations":"JSON routes missing the \"handler\" key; wrong inline key name for the module family; unregistered/misspelled module names in inline positions; nested module config errors reported one level down.","solutions":["Confirm the inline module-name key is present and correct in the JSON object (commonly \"handler\" for handlers, \"matcher\" for matchers)","Verify the module name value against `caddy list-modules` (the error shows the parsed name)","Address the inner %v error, which carries the precise LoadModuleByID failure (unknown module / decoding / provision / validate)","If adapting from Caddyfile, re-run `caddy adapt` to regenerate well-formed inline modules"],"exampleFix":"// before\n{ \"body\": \"hi\" } // handler key missing\n// after\n{ \"handler\": \"static_response\", \"body\": \"hi\" }","handlingStrategy":"validation","validationCode":"// Ensure inline objects carry the module-name key before loading\nfunc hasInlineKey(raw json.RawMessage, key string) bool {\n    var obj map[string]json.RawMessage\n    if err := json.Unmarshal(raw, &obj); err != nil { return false }\n    _, ok := obj[key]\n    return ok\n}","typeGuard":"func isInlineModule(raw json.RawMessage) bool {\n    var obj map[string]json.RawMessage\n    return json.Unmarshal(raw, &obj) == nil && len(obj) > 0\n}","tryCatchPattern":"if _, err := ctx.loadModuleInline(key, scope, raw); err != nil { return fmt.Errorf(\"inline module: %w\", err) } // quotes the parsed module name","preventionTips":["Always include the inline module-name key in object-form modules","Use `caddy adapt` output as the canonical shape reference","Confirm module names exist via `caddy list-modules`"],"tags":["caddy","module-system","json","config","inline-module"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}