{"record":{"id":"f5e22cbf161b859c","repo":"larksuite/cli","slug":"empty-version-output","errorCode":null,"errorMessage":"empty version output","messagePattern":"empty version output","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/selfupdate/updater.go","lineNumber":456,"sourceCode":"\texe, err := execLookPath(\"lark-cli\")\n\tif err != nil {\n\t\texe, err = vfs.Executable()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot locate binary: %w\", err)\n\t\t}\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), verifyTimeout)\n\tdefer cancel()\n\tout, err := exec.CommandContext(ctx, exe, \"--version\").Output()\n\tif ctx.Err() == context.DeadlineExceeded {\n\t\treturn fmt.Errorf(\"binary verification timed out after %s\", verifyTimeout)\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"binary not executable: %w\", err)\n\t}\n\tfields := strings.Fields(strings.TrimSpace(string(out)))\n\tif len(fields) == 0 {\n\t\treturn fmt.Errorf(\"empty version output\")\n\t}\n\tactual := strings.TrimPrefix(fields[len(fields)-1], \"v\")\n\texpected := strings.TrimPrefix(expectedVersion, \"v\")\n\tif actual != expected {\n\t\treturn fmt.Errorf(\"expected version %s, got %q\", expectedVersion, actual)\n\t}\n\treturn nil\n}\n\n// Truncate returns the last maxLen runes of s.\nfunc Truncate(s string, maxLen int) string {\n\tif maxLen <= 0 {\n\t\treturn \"\"\n\t}\n\tr := []rune(s)\n\tif len(r) <= maxLen {\n\t\treturn s\n\t}","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/selfupdate/updater.go#L438-L474","documentation":"After successfully running the new binary with `--version`, VerifyBinary tokenizes its stdout with strings.Fields and throws \"empty version output\" if there are no fields. This guards against installing a binary that runs but prints nothing on --version, which would make version verification meaningless.","triggerScenarios":"The executed binary exits with code 0 but writes no output (or only whitespace) to stdout, so strings.Fields on the trimmed output yields zero fields.","commonSituations":"The artifact is a stub or wrong file (e.g. an HTML error page saved as the binary that happens to run, a wrapper script echoing nothing); a repackaged binary whose --version prints to stderr instead of stdout; a build misconfiguration producing a no-op main().","solutions":["Check what the downloaded binary actually prints with `./binary --version`; fix the release artifact if it prints nothing","Ensure --version output goes to stdout (Output() only captures stdout)","Re-publish a correct release and re-run the update","Verify the download URL did not return an error page instead of the binary"],"exampleFix":"// before (Go binary prints version to stderr)\nfmt.Fprintf(os.Stderr, \"v%s\\n\", version) // empty stdout -> \"empty version output\"\n// after\nfmt.Printf(\"v%s\\n\", version) // stdout, e.g. \"mycli v1.2.3\"","handlingStrategy":"validation","validationCode":"out, err := exec.Command(binPath, \"--version\").Output()\nif err != nil { return err }\nif len(strings.Fields(strings.TrimSpace(string(out)))) == 0 {\n    return fmt.Errorf(\"binary %s prints no --version output\", binPath)\n}","typeGuard":null,"tryCatchPattern":"if err := update.VerifyBinary(ctx, path, expectedVersion); err != nil {\n    if strings.Contains(err.Error(), \"empty version output\") {\n        log.Printf(\"artifact at %s is not a valid CLI build; skipping auto-update\", path)\n    }\n    return err\n}","preventionTips":["Make --version print to stdout in every release build","Add a release CI step that installs the artifact and asserts non-empty --version output","Never point the updater at hand-edited or wrapper scripts","Log stdout/stderr of the verification run for diagnosis"],"tags":["selfupdate","version-verification","stdout"],"backgroundTag":"binary-verification-failed","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"}