{"record":{"id":"c22ec0e91dca36a8","repo":"coredns/coredns","slug":"invalid-type-q","errorCode":null,"errorMessage":"invalid type %q","messagePattern":"invalid type %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/rewrite/type.go","lineNumber":24,"sourceCode":"\t\"strings\"\n\n\t\"github.com/coredns/coredns/request\"\n\n\t\"github.com/miekg/dns\"\n)\n\n// typeRule is a type rewrite rule.\ntype typeRule struct {\n\tfromType   uint16\n\ttoType     uint16\n\tnextAction string\n}\n\nfunc newTypeRule(nextAction string, args ...string) (Rule, error) {\n\tvar from, to uint16\n\tvar ok bool\n\tif from, ok = dns.StringToType[strings.ToUpper(args[0])]; !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type %q\", strings.ToUpper(args[0]))\n\t}\n\tif to, ok = dns.StringToType[strings.ToUpper(args[1])]; !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type %q\", strings.ToUpper(args[1]))\n\t}\n\treturn &typeRule{from, to, nextAction}, nil\n}\n\n// Rewrite rewrites the current request.\nfunc (rule *typeRule) Rewrite(_ctx context.Context, state request.Request) (ResponseRules, Result) {\n\tif rule.fromType > 0 && rule.toType > 0 {\n\t\tif state.QType() == rule.fromType {\n\t\t\tstate.Req.Question[0].Qtype = rule.toType\n\t\t\treturn nil, RewriteDone\n\t\t}\n\t}\n\treturn nil, RewriteIgnored\n}\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/coredns/coredns/blob/558c9757a92b361e550bdba82d0b4ddf3d12d595/plugin/rewrite/type.go#L6-L42","documentation":"CoreDNS's rewrite plugin builds type-rewrite rules by looking both DNS type names up in miekg/dns's dns.StringToType map (after uppercasing the argument). If the first argument of the rule ('from' type) is not a recognized DNS RR type name, the rule cannot be constructed and construction aborts with this error. The check happens at Corefile parse/setup time, so the whole server fails to start rather than failing per-query.","triggerScenarios":"A Corefile contains a 'rewrite type' rule whose first argument (the type to match) is not a valid DNS type string, e.g. 'rewrite type foo A' or 'rewrite type CNAME' with no second argument (args[1] missing/empty makes args[0] also be checked and args[1] lookup fails on 271, but args[0] lookup fails here for garbage names).","commonSituations":"Typos in Corefile (e.g. 'rewrite type AA A' intending A), using pseudo-type names not present in StringToType, or truncating the two-argument form so args[1] equals the same invalid token.","solutions":["Fix the first 'type' argument in the rewrite rule to a valid DNS RR type name (A, AAAA, CNAME, MX, TXT, SRV, etc.)","Check spelling/case — lookup uppercases the value, so case is not the issue, only the name itself","Run corefile validation (coredns -conf Corefile) before deploying to catch the error at startup","If the type is genuinely needed but not in StringToType, upgrade CoreDNS/dns library to a version that knows the type"],"exampleFix":"// before (Corefile)\nrewrite type AA A\n// after\nrewrite type A AAAA","handlingStrategy":"validation","validationCode":"func validDNSType(t string) bool { _, ok := dns.StringToType[strings.ToUpper(t)]; return ok }\n// check before writing the rule: if !validDNSType(arg0) { reject }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate Corefile rewrite rules with coredns -conf before deploying","Keep a list of valid RR type names (dns.StringToType keys) handy when writing rules","Always supply both from and to arguments for 'rewrite type' rules"],"tags":["dns","config","coredns","rewrite"],"backgroundTag":"invalid-config-value","analyzedSha":"558c9757a92b361e550bdba82d0b4ddf3d12d595","analyzedAt":"2026-09-06T22:47:02.106Z","contentChangedAt":"2026-09-06T22:47:02.106Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}