all repos

clerk @ 45890c9deddb940b6a20bad3de4827a0058b8396

missing tooling for ledger/hledger
4 files changed, 18 insertions(+), 18 deletions(-)
cli: deduplicate error reporting, - use cli.Exit for expected errors
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-07-11 12:51:53 +0300
Authored at: 2026-06-28 22:49:13 +0300
Change ID: wxtquwtowptrqsrnutorxpqltyzzmtpz
Parent: a65ac05
M internal/cli/cmd_format.go
···
        32
        32
         			for _, fe := range pf.FileErrors {

      
        33
        33
         				fmt.Fprintf(os.Stderr, "error: stdin: %s\n", fe.Message)

      
        34
        34
         			}

      
        35
        
        -			return fmt.Errorf("stdin: has errors, refusing to format")

      
        
        35
        +			return cli.Exit("", 1)

      
        36
        36
         		}

      
        37
        37
         		return c.formatFile("stdin", pf, check, diff, list, write)

      
        38
        38
         	}

      ···
        42
        42
         		return err

      
        43
        43
         	}

      
        44
        44
         

      
        45
        
        -	var errs []error

      
        
        45
        +	var hasErrors bool

      
        46
        46
         	for _, path := range files {

      
        47
        47
         		pf, err := loadFile(loader, path)

      
        48
        48
         		if err != nil {

      
        49
        49
         			fmt.Fprintf(os.Stderr, "error: %v\n", err)

      
        50
        
        -			errs = append(errs, err)

      
        
        50
        +			hasErrors = true

      
        51
        51
         			continue

      
        52
        52
         		}

      
        53
        53
         		if len(pf.Errors) > 0 || len(pf.FileErrors) > 0 {

      ···
        57
        57
         			for _, fe := range pf.FileErrors {

      
        58
        58
         				fmt.Fprintf(os.Stderr, "error: %s: %s\n", path, fe.Message)

      
        59
        59
         			}

      
        60
        
        -			errs = append(errs, fmt.Errorf("%s: has errors, refusing to format", path))

      
        
        60
        +			hasErrors = true

      
        61
        61
         			continue

      
        62
        62
         		}

      
        63
        63
         

      
        64
        64
         		if err := c.formatFile(path, pf, check, diff, list, write); err != nil {

      
        65
        65
         			fmt.Fprintf(os.Stderr, "error: %s: %v\n", path, err)

      
        66
        
        -			errs = append(errs, err)

      
        
        66
        +			hasErrors = true

      
        67
        67
         		}

      
        68
        68
         	}

      
        69
        
        -	if len(errs) > 0 {

      
        70
        
        -		return fmt.Errorf("format: %d error(s)", len(errs))

      
        
        69
        +	if hasErrors {

      
        
        70
        +		return cli.Exit("", 1)

      
        71
        71
         	}

      
        72
        72
         	return nil

      
        73
        73
         }

      
M internal/cli/cmd_lint.go
···
        35
        35
         

      
        36
        36
         	loader := journal.NewLoader()

      
        37
        37
         

      
        38
        
        -	var errs []error

      
        
        38
        +	var hasIssues bool

      
        39
        39
         	for _, f := range journalFiles {

      
        40
        40
         		if _, err := loadFile(loader, f); err != nil {

      
        41
        41
         			fmt.Fprintf(os.Stderr, "error: %v\n", err)

      
        42
        
        -			errs = append(errs, err)

      
        
        42
        +			hasIssues = true

      
        43
        43
         		}

      
        44
        44
         	}

      
        45
        45
         

      ···
        50
        50
         		return fmt.Errorf("flushing report: %w", err)

      
        51
        51
         	}

      
        52
        52
         

      
        53
        
        -	if reporter.HasIssues() || len(errs) > 0 {

      
        54
        
        -		return fmt.Errorf("lint found issues")

      
        
        53
        +	if reporter.HasIssues() || hasIssues {

      
        
        54
        +		return cli.Exit("", 1)

      
        55
        55
         	}

      
        56
        56
         	return nil

      
        57
        57
         }

      ···
        69
        69
         		return fmt.Errorf("flushing report: %w", err)

      
        70
        70
         	}

      
        71
        71
         	if reporter.HasIssues() {

      
        72
        
        -		return fmt.Errorf("lint found issues")

      
        
        72
        +		return cli.Exit("", 1)

      
        73
        73
         	}

      
        74
        74
         	return nil

      
        75
        75
         }

      
M internal/cli/cmd_tags.go
···
        34
        34
         

      
        35
        35
         	loader := journal.NewLoader()

      
        36
        36
         

      
        37
        
        -	var errs []error

      
        
        37
        +	var hasErrors bool

      
        38
        38
         	for _, file := range journalFiles {

      
        39
        39
         		if _, err := loadFile(loader, file); err != nil {

      
        40
        40
         			fmt.Fprintf(os.Stderr, "error: %v\n", err)

      
        41
        
        -			errs = append(errs, err)

      
        
        41
        +			hasErrors = true

      
        42
        42
         		}

      
        43
        43
         	}

      
        44
        
        -	if len(errs) > 0 {

      
        45
        
        -		return fmt.Errorf("tags: %d errors", len(errs))

      
        
        44
        +	if hasErrors {

      
        
        45
        +		return cli.Exit("", 1)

      
        46
        46
         	}

      
        47
        47
         

      
        48
        48
         	tagger := tags.New(loader, cwd)

      
M main.go
···
        2
        2
         

      
        3
        3
         import (

      
        4
        4
         	"context"

      
        5
        
        -	"log/slog"

      
        
        5
        +	"fmt"

      
        6
        6
         	"os"

      
        7
        7
         

      
        8
        8
         	"olexsmir.xyz/clerk/internal/cli"

      ···
        14
        14
         

      
        15
        15
         func main() {

      
        16
        16
         	if err := cli.New(version).Run(context.Background(), os.Args); err != nil {

      
        17
        
        -		slog.Error("mugit", "err", err)

      
        
        17
        +		fmt.Fprintf(os.Stderr, "error: %v\n", err)

      
        18
        18
         		os.Exit(1)

      
        19
        19
         	}

      
        20
        20
         }