{"id":"11135b58b13f5912","repo":"spf13/cobra","slug":"invalid-source-date-epoch-v","errorCode":null,"errorMessage":"invalid SOURCE_DATE_EPOCH: %v","messagePattern":"invalid SOURCE_DATE_EPOCH: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"doc/man_docs.go","lineNumber":130,"sourceCode":"\n\tb := genMan(cmd, header)\n\t_, err := w.Write(md2man.Render(b))\n\treturn err\n}\n\nfunc fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {\n\tif header.Title == \"\" {\n\t\theader.Title = strings.ToUpper(strings.ReplaceAll(name, \" \", \"\\\\-\"))\n\t}\n\tif header.Section == \"\" {\n\t\theader.Section = \"1\"\n\t}\n\tif header.Date == nil {\n\t\tnow := time.Now()\n\t\tif epoch := os.Getenv(\"SOURCE_DATE_EPOCH\"); epoch != \"\" {\n\t\t\tunixEpoch, err := strconv.ParseInt(epoch, 10, 64)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid SOURCE_DATE_EPOCH: %v\", err)\n\t\t\t}\n\t\t\tnow = time.Unix(unixEpoch, 0)\n\t\t}\n\t\theader.Date = &now\n\t}\n\theader.date = header.Date.Format(\"Jan 2006\")\n\tif header.Source == \"\" && !disableAutoGen {\n\t\theader.Source = \"Auto generated by spf13/cobra\"\n\t}\n\treturn nil\n}\n\nfunc manPreamble(buf io.StringWriter, header *GenManHeader, cmd *cobra.Command, dashedName string) {\n\tdescription := cmd.Long\n\tif len(description) == 0 {\n\t\tdescription = cmd.Short\n\t}\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/spf13/cobra/blob/adbc8813901bba65827259daa8e22ff94ec1f30e/doc/man_docs.go#L112-L148","documentation":"Returned by fillHeader (used by GenMan / man-page generation) when the SOURCE_DATE_EPOCH environment variable is set but cannot be parsed as a base-10 64-bit integer. SOURCE_DATE_EPOCH is the reproducible-builds convention for pinning the date embedded in generated man pages; cobra honours it only when header.Date is nil (i.e. the caller did not supply a date).","triggerScenarios":"Exporting SOURCE_DATE_EPOCH with a non-numeric, negative, empty-after-export, or overflow value, then calling doc.GenManTree / GenMan. strconv.ParseInt(epoch, 10, 64) fails on anything but an optional-signed decimal integer in int64 range.","commonSituations":"CI/build environments setting SOURCE_DATE_EPOCH from a git timestamp that is empty or formatted (e.g. with a timezone), a stray unit suffix, or a value copied from a different reproducible-builds tool with incompatible formatting.","solutions":["Set SOURCE_DATE_EPOCH to a valid Unix epoch integer (seconds since 1970-01-01), e.g. `git log -1 --format=%ct`.","Unset the variable if reproducible dates aren't needed; cobra will then use time.Now().","Alternatively, pass a non-nil header.Date to GenMan so the env-var path is skipped entirely.","Validate the value in your build script before invoking doc generation."],"exampleFix":"# before\nexport SOURCE_DATE_EPOCH=\"2024-01-01\"\n# -> invalid SOURCE_DATE_EPOCH: ...\n\n# after\nexport SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)","handlingStrategy":"validation","validationCode":"// Validate SOURCE_DATE_EPOCH before generating man pages\nfunc checkedEpoch() (int64, error) {\n    v := os.Getenv(\"SOURCE_DATE_EPOCH\")\n    if v == \"\" { return 0, nil }\n    n, err := strconv.ParseInt(v, 10, 64)\n    if err != nil {\n        return 0, fmt.Errorf(\"SOURCE_DATE_EPOCH must be a Unix timestamp; got %q\", v)\n    }\n    return n, nil\n}","typeGuard":"null","tryCatchPattern":"if err := doc.GenManTree(cmd, header, dir); err != nil {\n    if strings.Contains(err.Error(), \"SOURCE_DATE_EPOCH\") {\n        os.Unsetenv(\"SOURCE_DATE_EPOCH\"); err = doc.GenManTree(cmd, header, dir)\n    }\n}","preventionTips":["Derive SOURCE_DATE_EPOCH from `git log -1 --format=%ct` in CI.","Skip the env var by passing a non-nil header.Date to GenMan.","Validate the value in the build script before invoking doc generation."],"tags":["docs","man","env","reproducible-build","cobra"],"analyzedSha":"adbc8813901bba65827259daa8e22ff94ec1f30e","analyzedAt":"2026-08-04T21:41:27.617Z","schemaVersion":2}