{"record":{"id":"3b0d8352e2fc0dda","repo":"larksuite/cli","slug":"busdiscover-malformed-timestamp-in-s-w","errorCode":null,"errorMessage":"busdiscover: malformed timestamp in %s: %w","messagePattern":"busdiscover: malformed timestamp in (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/event/adapter/localbus/busdiscover/pidfile.go","lineNumber":78,"sourceCode":"}\n\nfunc readPIDFile(eventsDir string) (int, time.Time, error) {\n\tpidPath := filepath.Join(eventsDir, pidFileName)\n\tdata, err := vfs.ReadFile(pidPath)\n\tif err != nil {\n\t\treturn 0, time.Time{}, err\n\t}\n\tlines := strings.SplitN(strings.TrimSpace(string(data)), \"\\n\", 2)\n\tif len(lines) < 2 {\n\t\treturn 0, time.Time{}, fmt.Errorf(\"busdiscover: malformed pid file %s\", pidPath)\n\t}\n\tpid, err := strconv.Atoi(strings.TrimSpace(lines[0]))\n\tif err != nil {\n\t\treturn 0, time.Time{}, fmt.Errorf(\"busdiscover: malformed pid in %s: %w\", pidPath, err)\n\t}\n\tstartTime, err := time.Parse(time.RFC3339, strings.TrimSpace(lines[1]))\n\tif err != nil {\n\t\treturn 0, time.Time{}, fmt.Errorf(\"busdiscover: malformed timestamp in %s: %w\", pidPath, err)\n\t}\n\treturn pid, startTime, nil\n}\n\n// isBusAlive: try-lock the alive file. ErrHeld = live holder; success = stale (release immediately).\nfunc isBusAlive(appDir string) bool {\n\tlockPath := filepath.Join(appDir, aliveLockFileName)\n\tif _, err := vfs.Stat(lockPath); err != nil {\n\t\treturn false\n\t}\n\tprobe := lockfile.New(lockPath)\n\terr := probe.TryLock()\n\tif errors.Is(err, lockfile.ErrHeld) {\n\t\treturn true\n\t}\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"[busdiscover] probe %s: %v\\n\", lockPath, err) //nolint:forbidigo // internal diagnostic; scanner has no IOStreams plumbing\n\t\treturn false","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/adapter/localbus/busdiscover/pidfile.go#L60-L96","documentation":"readPIDFile wraps strconv/time parse failures when reading a bus pidfile. The first line must be an integer PID and the second line an RFC3339 timestamp; if either fails to parse, the pidfile is considered corrupt and the error reports the file path plus the underlying parse cause via %w.","triggerScenarios":"scanLiveBuses encounters a pidfile whose line 1 is not a decimal integer (raises 'malformed pid') or whose line 2 is not a valid time.RFC3339 timestamp (raises 'malformed timestamp').","commonSituations":"A bus process crashed mid-write leaving a truncated pidfile; a user or script hand-edited the pidfile; the file contains a timestamp with wrong format (e.g. unix epoch number or local time string instead of RFC3339 like '2026-09-04T12:00:00Z'); an empty or whitespace-only second line after a partial write.","solutions":["Delete the corrupt pidfile (or the whole stale bus directory under eventsDir) so scanLiveBuses skips it and a fresh bus can rewrite it","Check the pidfile content: line 1 must be an integer PID, line 2 must be RFC3339 (e.g. 2026-09-04T10:00:00Z); fix or regenerate it","Ensure no concurrent writers truncate the file while the bus starts; verify the process that writes the pidfile completes atomically (write-then-rename)","Confirm clock/timezone tooling used to generate the timestamp emits RFC3339 with Z or offset"],"exampleFix":"// before (corrupt pidfile)\n12345\n2026-09-04 10:00:00\n// after (valid pidfile)\n12345\n2026-09-04T10:00:00Z","handlingStrategy":"validation","validationCode":"func validPIDFile(path string) bool {\n\tb, err := os.ReadFile(path)\n\tif err != nil || len(b) == 0 {\n\t\treturn false\n\t}\n\tlines := strings.Split(strings.TrimSpace(string(b)), \"\\n\")\n\tif len(lines) < 2 {\n\t\treturn false\n\t}\n\tif _, err := strconv.Atoi(strings.TrimSpace(lines[0])); err != nil {\n\t\treturn false\n\t}\n\t_, err = time.Parse(time.RFC3339, strings.TrimSpace(lines[1]))\n\treturn err == nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write the pidfile atomically: write to a temp file then os.Rename over the target","Always format timestamps with time.Now().UTC().Format(time.RFC3339)","Never hand-edit pidfiles; delete and let the bus recreate them","Add a health check that validates pidfile shape before depending on it"],"tags":["go","localbus","pidfile","timestamp-parse"],"backgroundTag":"malformed-timestamp","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}