txthinking/brook · error

invalid type

Error message

invalid type

What it means

The `brook dns` subcommand looks up c.String("type") in the miekg/dns StringToType map to convert the record-type flag into a dns.Type constant. If the string is not a recognized DNS record type (e.g. not A, AAAA, CNAME, TXT, MX...), brook throws "invalid type" before issuing the query.

Source

Thrown at cli/brook/main.go:1985

					Name:  "short",
					Usage: "Short for A/AAAA",
				},
				&cli.BoolFlag{
					Name:  "example",
					Usage: "Show a minimal example of usage",
				},
			},
			Action: func(c *cli.Context) error {
				if c.Bool("example") {
					fmt.Println("brook dnsclient --domain google.com")
					return nil
				}
				if c.String("domain") == "" {
					return cli.ShowSubcommandHelp(c)
				}
				t, ok := dns.StringToType[c.String("type")]
				if !ok {
					return errors.New("invalid type")
				}
				dc := &brook.DNSClient{Server: c.String("dns")}
				m := &dns.Msg{}
				m.SetQuestion(strings.TrimRight(c.String("domain"), ".")+".", t)
				m, err := dc.Exchange(m)
				if err != nil {
					return err
				}
				if c.Bool("short") && (c.String("type") == "A" || c.String("type") == "AAAA") {
					for _, v := range m.Answer {
						if t, ok := v.(*dns.A); ok {
							fmt.Println(t.A)
							return nil
						}
						if t, ok := v.(*dns.AAAA); ok {
							fmt.Println(t.AAAA)
							return nil
						}

View on GitHub (pinned to 5cd13ef3b1)

Solutions

  1. Use the exact uppercase mnemonics: --type A, AAAA, CNAME, MX, TXT, NS, SRV, PTR, SOA
  2. Omit --type entirely if a default (A) is acceptable, per subcommand help
  3. Print valid types via the dns library's TypeToString conventions to pick a correct value

Example fix

// before
brook dns --dns 8.8.8.8:53 --domain example.com --type a
// after
brook dns --dns 8.8.8.8:53 --domain example.com --type A
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: Running `brook dns --domain example.com --type a` (lowercase, not in dns.StringToType) or `--type A-RECORD` or any misspelled type at cli/brook/main.go:1985.

Common situations: Using lowercase type names like `a` or `cname`; using pseudo-type names like ANY/AXFR that the map may not contain in that form; scripting with a variable that is empty so --type resolves to "".

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06). Data as JSON: /api/errors/b3a08323d371878c. Report an issue: GitHub.