{"record":{"id":"18b41f0ef791e26b","repo":"robfig/cron","slug":"provided-bad-location-s-v","errorCode":null,"errorMessage":"provided bad location %s: %v","messagePattern":"provided bad location (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"parser.go","lineNumber":100,"sourceCode":"\treturn Parser{options}\n}\n\n// Parse returns a new crontab schedule representing the given spec.\n// It returns a descriptive error if the spec is not valid.\n// It accepts crontab specs and features configured by NewParser.\nfunc (p Parser) Parse(spec string) (Schedule, error) {\n\tif len(spec) == 0 {\n\t\treturn nil, fmt.Errorf(\"empty spec string\")\n\t}\n\n\t// Extract timezone if present\n\tvar loc = time.Local\n\tif strings.HasPrefix(spec, \"TZ=\") || strings.HasPrefix(spec, \"CRON_TZ=\") {\n\t\tvar err error\n\t\ti := strings.Index(spec, \" \")\n\t\teq := strings.Index(spec, \"=\")\n\t\tif loc, err = time.LoadLocation(spec[eq+1 : i]); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"provided bad location %s: %v\", spec[eq+1:i], err)\n\t\t}\n\t\tspec = strings.TrimSpace(spec[i:])\n\t}\n\n\t// Handle named schedules (descriptors), if configured\n\tif strings.HasPrefix(spec, \"@\") {\n\t\tif p.options&Descriptor == 0 {\n\t\t\treturn nil, fmt.Errorf(\"parser does not accept descriptors: %v\", spec)\n\t\t}\n\t\treturn parseDescriptor(spec, loc)\n\t}\n\n\t// Split on whitespace.\n\tfields := strings.Fields(spec)\n\n\t// Validate & fill in any omitted or optional fields\n\tvar err error\n\tfields, err = normalizeFields(fields, p.options)","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/robfig/cron/blob/bc59245fe10efaed9d51b56900192527ed733435/parser.go#L82-L118","documentation":"When the spec starts with TZ= or CRON_TZ=, Parse extracts the location name between '=' and the first space and loads it with time.LoadLocation. If the name is not a valid IANA timezone (or tzdata is unavailable), the parse fails with this formatted error.","triggerScenarios":"Parsing specs like \"TZ=Bad/Zone * * * *\" or \"CRON_TZ=UTCX 0 0 * * *\" where the location name is misspelled or unknown.","commonSituations":"Typo in timezone name in a cron config; deploying to a minimal Docker image (scratch/alpine) without tzdata so even valid names fail; building without importing time/tzdata.","solutions":["Correct the timezone name to a valid IANA identifier (e.g. America/New_York, UTC)","Install tzdata in the deployment image (apk add tzdata, apt install tzdata)","Import _ \"time/tzdata\" in Go to embed the timezone database in the binary","Validate the location with time.LoadLocation before calling Parse"],"exampleFix":"// before\nsched, _ := parser.Parse(\"TZ=Pacific/Ocean * * * * *\")\n// after\nif _, err := time.LoadLocation(\"Pacific/Auckland\"); err == nil {\n    sched, _ = parser.Parse(\"TZ=Pacific/Auckland * * * * *\")\n}","handlingStrategy":"validation","validationCode":"if i := strings.Index(spec, \"=\"); strings.HasPrefix(spec, \"TZ=\") || strings.HasPrefix(spec, \"CRON_TZ=\") {\n\tif _, err := time.LoadLocation(spec[i+1:strings.Index(spec, \" \")]); err != nil {\n\t\treturn fmt.Errorf(\"unknown timezone: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"sched, err := parser.Parse(spec)\nvar locErr *time.ParseError\nif errors.As(err, nil) || strings.Contains(err.Error(), \"bad location\") {\n\treturn fmt.Errorf(\"check TZ= in cron spec: %w\", err)\n}","preventionTips":["Validate timezone names against time.LoadLocation at startup","Install tzdata or import _ \"time/tzdata\" for containers","Restrict user-supplied timezone input to a whitelist"],"tags":["go","cron","timezone","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"bc59245fe10efaed9d51b56900192527ed733435","analyzedAt":"2026-09-07T00:35:06.760Z","contentChangedAt":"2026-09-07T00:35:06.760Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}