{"record":{"id":"e5210ee676bc3090","repo":"multica-ai/multica","slug":"days-must-be-between-1-and-365","errorCode":null,"errorMessage":"--days must be between 1 and 365","messagePattern":"--days must be between 1 and 365","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/cmd/multica/cmd_runtime.go","lineNumber":150,"sourceCode":"\t\t\tstrVal(rt, \"runtime_mode\"),\n\t\t\tstrVal(rt, \"provider\"),\n\t\t\tstrVal(rt, \"status\"),\n\t\t\tstrVal(rt, \"last_seen_at\"),\n\t\t})\n\t}\n\tcli.PrintTable(os.Stdout, headers, rows)\n\treturn nil\n}\n\nfunc runRuntimeUsage(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tdays, _ := cmd.Flags().GetInt(\"days\")\n\tif days < 1 || days > 365 {\n\t\treturn fmt.Errorf(\"--days must be between 1 and 365\")\n\t}\n\n\tctx, cancel := cli.APIContext(context.Background())\n\tdefer cancel()\n\n\tvar usage []map[string]any\n\tpath := fmt.Sprintf(\"/api/runtimes/%s/usage?days=%d\", args[0], days)\n\tif err := client.GetJSON(ctx, path, &usage); err != nil {\n\t\treturn fmt.Errorf(\"get runtime usage: %w\", err)\n\t}\n\n\toutput, _ := cmd.Flags().GetString(\"output\")\n\tif output == \"json\" {\n\t\treturn cli.PrintJSON(os.Stdout, usage)\n\t}\n\n\theaders := []string{\"DATE\", \"PROVIDER\", \"MODEL\", \"INPUT_TOKENS\", \"OUTPUT_TOKENS\", \"CACHE_READ\", \"CACHE_WRITE\"}\n\trows := make([][]string, 0, len(usage))","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_runtime.go#L132-L168","documentation":"Argument validation in runRuntimeUsage: the --days flag must be an integer in [1, 365]; anything outside — including 0, negatives, >365, or a non-integer that cobra fails to parse — is rejected before any network call. This bounds the usage-history window the server must aggregate.","triggerScenarios":"Running `multica runtime usage <id> --days 0`, `--days 400`, `--days -7`, or `--days 30days` (parse error surfaces via the flag binding, then range check catches valid ints out of range).","commonSituations":"Scripts parameterizing days from an unset variable (defaults to 0); users asking for a year+ of history (--days 366); copy-paste of ISO durations like 30d.","solutions":["Pass an integer between 1 and 365, e.g. --days 30.","Clamp scripted input: days=$(( days<1 ? 1 : (days>365 ? 365 : days) )).","For longer horizons, query the API directly or aggregate two windows (e.g. days 1-365 twice with date offsets) — the CLI cap mirrors the server's."],"exampleFix":"# before\nmultica runtime usage rt_123 --days 0\n\n# after\nmultica runtime usage rt_123 --days 30","handlingStrategy":"validation","validationCode":"days, err := cmd.Flags().GetInt(\"days\")\nif err != nil || days < 1 || days > 365 {\n\treturn fmt.Errorf(\"--days must be an integer between 1 and 365, got %d\", days)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp scripted inputs before passing them.","Treat unset shell variables (0) as 30 with ${DAYS:-30}.","Remember the cap mirrors the server; do not try to bypass via the API."],"tags":["go","cli","flag-validation","range-check","usage-error"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}