{"record":{"id":"c56709acb1363abb","repo":"vitessio/vitess","slug":"this-command-panics-on-purpose","errorCode":null,"errorMessage":"this command panics on purpose","messagePattern":"this command panics on purpose","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"go/vt/vtctl/vtctl.go","lineNumber":3919,"sourceCode":"}\n\nfunc commandGenerateShardRanges(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {\n\tnumShards := subFlags.Int(\"num_shards\", 2, \"Number of shards to generate shard ranges for.\")\n\n\tif err := subFlags.Parse(args); err != nil {\n\t\treturn err\n\t}\n\n\tshardRanges, err := key.GenerateShardRanges(*numShards, 0)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn printJSON(wr.Logger(), shardRanges)\n}\n\nfunc commandPanic(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error {\n\tpanic(errors.New(\"this command panics on purpose\"))\n}\n\n// printJSON will print the JSON version of the structure to the logger.\nfunc printJSON(logger logutil.Logger, val any) error {\n\tdata, err := MarshalJSON(val)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot marshal data: %v\", err)\n\t}\n\tlogger.Printf(\"%s\\n\", data)\n\treturn nil\n}\n\n// loggerWriter turns a Logger into a Writer by decorating it with a Write()\n// method that sends everything to Logger.Printf().\ntype loggerWriter struct {\n\tlogutil.Logger\n}\n","sourceCodeStart":3901,"sourceCodeEnd":3937,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/vtctl.go#L3901-L3937","documentation":"commandPanic is a debugging/diagnostic command that deliberately panics with this error. It exists so operators and developers can verify vtctld's panic-recovery, error reporting, and client behavior on unexpected panics. It is not a real failure of any subsystem.","triggerScenarios":"Running the `vtctl Panic` (or vtctldclient equivalent) command: `commandPanic` unconditionally panics with errors.New(\"this command panics on purpose\").","commonSituations":"Testing monitoring/alerting pipelines, verifying that vtctld returns a proper gRPC INTERNAL error on panics, or verifying client stack traces; rarely hit accidentally.","solutions":["This is expected behavior of the Panic command — no fix needed; simply do not run the Panic command in production","If hit accidentally, verify nothing else is wrong; the panic is self-inflicted and contained by vtctld's recovery"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if cmd == \"Panic\" {\n    log.Warn(\"running deliberate-panic command; expected failure\")\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Warn(\"recovered deliberate vtctl panic\", slog.Any(\"panic\", r))\n    }\n}()","preventionTips":["Exclude the Panic command from production runbooks and tooling","Use it only in controlled tests of panic recovery","Add allowlists of permitted vtctl commands in automation"],"tags":["vtctl","panic","debugging","intentional"],"backgroundTag":"intentional-panic-command","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}