From cdcbd245d75572fcb537a3d87ceef8f864d7096b Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sun, 1 Mar 2026 14:14:55 +0000 Subject: [PATCH] fix(cmd): add error handling for user input in edit and lint commands - Handle errors from fmt.Scanln in cmd/edit.go and cmd/lint.go to prevent crashes on input failures, providing user feedback and preserving backups. - Update .gitea/workflows/release.yml to use 'ubuntu-gitea' runner for CI consistency. --- .gitea/workflows/release.yml | 2 +- cmd/edit.go | 6 +++++- cmd/lint.go | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 857804b..4f7547a 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -11,7 +11,7 @@ permissions: jobs: release: name: Create Release - runs-on: ubuntu-latest + runs-on: ubuntu-gitea steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/cmd/edit.go b/cmd/edit.go index 1ebedff..69df99b 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -71,7 +71,11 @@ var editCmd = &cobra.Command{ fmt.Print("\n\nApply these changes? (y/n): ") var confirm string - fmt.Scanln(&confirm) + if _, err := fmt.Scanln(&confirm); err != nil { + color.Red("Failed to read input: %v", err) + color.Yellow("Changes discarded. Backup saved as %s", backupPath) + return + } if confirm != "y" && confirm != "Y" { color.Yellow("Changes discarded. Backup saved as %s", backupPath) return diff --git a/cmd/lint.go b/cmd/lint.go index 4f4b434..322aec5 100644 --- a/cmd/lint.go +++ b/cmd/lint.go @@ -165,7 +165,11 @@ func runLint(cmd *cobra.Command, args []string) { // Ask for confirmation color.Yellow("Apply these fixes? (y/N): ") var response string - fmt.Scanln(&response) + if _, err := fmt.Scanln(&response); err != nil { + logger.Info("failed to read user input", "file", absPath, "error", err) + color.Yellow("❌ Cancelled. Backup preserved at: %s", backupPath) + return + } response = strings.ToLower(strings.TrimSpace(response)) if response != "y" && response != "yes" {