From 144d2de24331b3c7c28ee1120bfa4f3d3fcee4de Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 2 Feb 2026 13:43:18 -0800 Subject: [PATCH] Return error when stdin provides no paths When using "-" to read paths from stdin, if stdin is empty or contains only blank lines, return an explicit error instead of silently succeeding with no work done. --- attrsum.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/attrsum.go b/attrsum.go index 2510909..1479ed5 100644 --- a/attrsum.go +++ b/attrsum.go @@ -99,8 +99,10 @@ func main() { // expandPaths expands the given paths, reading from stdin if "-" is present func expandPaths(args []string) ([]string, error) { var paths []string + readFromStdin := false for _, arg := range args { if arg == "-" { + readFromStdin = true scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) @@ -115,6 +117,12 @@ func expandPaths(args []string) ([]string, error) { paths = append(paths, arg) } } + if len(paths) == 0 { + if readFromStdin { + return nil, errors.New("no paths provided on stdin") + } + return nil, errors.New("no paths provided") + } return paths, nil }