Skip to content

Commit 967c37a

Browse files
authored
Merge pull request #122 from initia-labs/impv/error-cmd
Improve error not show exit code 1
2 parents 72df329 + e2ca7e8 commit 967c37a

File tree

6 files changed

+31
-26
lines changed

6 files changed

+31
-26
lines changed

cmd/opinit_bots.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ func OPInitBotsResetCommand() *cobra.Command {
513513
})
514514
analytics.TrackRunEvent(cmd, args, analytics.ResetOPinitBotFeature, analytics.NewEmptyEvent())
515515
execCmd := exec.Command(binaryPath, "reset-db", botName)
516-
if err = execCmd.Run(); err != nil {
517-
return fmt.Errorf("failed to reset-db: %v", err)
516+
if output, err := execCmd.CombinedOutput(); err != nil {
517+
return fmt.Errorf("failed to reset-db: %v (output: %s)", err, string(output))
518518
}
519519
analytics.TrackCompletedEvent(analytics.ResetOPinitBotFeature)
520520
fmt.Printf("Reset the OPinit %s bot database successfully.\n", botName)

cosmosutils/keys.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ func OPInitGrantOracle(appName, address, opInitHome string) error {
195195
var stderr bytes.Buffer
196196
cmd.Stderr = &stderr
197197

198-
if err := cmd.Run(); err != nil {
199-
return fmt.Errorf("failed to grant oracle to address %s: %v, stderr: %s", address, err, stderr.String())
198+
if output, err := cmd.CombinedOutput(); err != nil {
199+
return fmt.Errorf("failed to grant oracle to address %s: %v (output: %s)", address, err, string(output))
200200
}
201201

202202
return nil
@@ -357,8 +357,8 @@ func GetHermesRelayerAddress(appName, chainId string) (string, bool) {
357357

358358
func DeleteWeaveKeyFromHermes(appName, chainId string) error {
359359
cmd := exec.Command(appName, "keys", "delete", "--chain", chainId, "--key-name", "weave-relayer")
360-
if err := cmd.Run(); err != nil {
361-
return fmt.Errorf("failed to delete key from hermes for network: %s: %v", chainId, err)
360+
if output, err := cmd.CombinedOutput(); err != nil {
361+
return fmt.Errorf("failed to delete key from hermes for network: %s: %v (output: %s)", chainId, err, string(output))
362362
}
363363

364364
return nil

models/initia/run_l1_node.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,17 +1092,17 @@ func initializeApp(ctx context.Context) tea.Cmd {
10921092
}
10931093
if _, err := os.Stat(initiaHome); os.IsNotExist(err) {
10941094
runCmd := exec.Command(binaryPath, "init", fmt.Sprintf("'%s'", state.moniker), "--chain-id", state.chainId, "--home", initiaHome)
1095-
if err := runCmd.Run(); err != nil {
1096-
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run initiad init: %v", err)}
1095+
if output, err := runCmd.CombinedOutput(); err != nil {
1096+
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run initiad init: %v (output: %s)", err, string(output))}
10971097
}
10981098

10991099
}
11001100

11011101
if _, err = os.Stat(filepath.Join(initiaHome, "cosmovisor")); os.IsNotExist(err) {
11021102
runCmd := exec.Command(cosmovisorPath, "init", binaryPath)
11031103
runCmd.Env = append(runCmd.Env, "DAEMON_NAME=initiad", "DAEMON_HOME="+initiaHome)
1104-
if err := runCmd.Run(); err != nil {
1105-
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run cosmovisor init: %v", err)}
1104+
if output, err := runCmd.CombinedOutput(); err != nil {
1105+
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run cosmovisor init: %v (output: %s)", err, string(output))}
11061106
}
11071107
}
11081108

@@ -1182,8 +1182,8 @@ func initializeApp(ctx context.Context) tea.Cmd {
11821182

11831183
// Initialize the node in the temporary directory
11841184
initCmd := exec.Command(binaryPath, "init", state.moniker, "--chain-id", state.chainId, "--home", tmpInitiaHome)
1185-
if err := initCmd.Run(); err != nil {
1186-
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run temporary initiad init: %v", err)}
1185+
if output, err := initCmd.CombinedOutput(); err != nil {
1186+
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run temporary initiad init: %v (output: %s)", err, string(output))}
11871187
}
11881188

11891189
// Move the temporary genesis.json file to the user Initia config path
@@ -1859,8 +1859,8 @@ func snapshotExtractor(ctx context.Context) tea.Cmd {
18591859
}
18601860
binaryPath := filepath.Join(userHome, common.WeaveDataDirectory, fmt.Sprintf("initia@%s", state.initiadVersion), "initiad")
18611861
runCmd := exec.Command(binaryPath, "comet", "unsafe-reset-all", "--keep-addr-book", "--home", initiaHome)
1862-
if err := runCmd.Run(); err != nil {
1863-
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run initiad comet unsafe-reset-all: %v", err)}
1862+
if output, err := runCmd.CombinedOutput(); err != nil {
1863+
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to run initiad comet unsafe-reset-all: %v (output: %s)", err, string(output))}
18641864
}
18651865

18661866
cmd := exec.Command("bash", "-c", fmt.Sprintf("lz4 -c -d %s | tar -x -C %s", filepath.Join(userHome, common.WeaveDataDirectory, common.SnapshotFilename), initiaHome))
@@ -1973,8 +1973,8 @@ func setupStateSync(ctx context.Context) tea.Cmd {
19731973
return ui.NonRetryableErrorLoading{Err: fmt.Errorf("[error] Failed to get initia binary path: %v", err)}
19741974
}
19751975
runCmd := exec.Command(binaryPath, "comet", "unsafe-reset-all", "--keep-addr-book", "--home", initiaHome)
1976-
if err := runCmd.Run(); err != nil {
1977-
return ui.ErrorLoading{Err: fmt.Errorf("failed to run initiad comet unsafe-reset-all: %v", err)}
1976+
if output, err := runCmd.CombinedOutput(); err != nil {
1977+
return ui.ErrorLoading{Err: fmt.Errorf("failed to run initiad comet unsafe-reset-all: %v (output: %s)", err, string(output))}
19781978
}
19791979

19801980
return ui.EndLoading{}

models/minitia/launch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,8 +3120,8 @@ func (m *LaunchingNewMinitiaLoading) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
31203120
"--from", "Validator", "--keyring-backend", "test",
31213121
"--chain-id", state.chainId, "-y",
31223122
)
3123-
if err := runCmd.Run(); err != nil {
3124-
return m, m.HandlePanic(fmt.Errorf("failed to update params message: %v", err))
3123+
if output, err := runCmd.CombinedOutput(); err != nil {
3124+
return m, m.HandlePanic(fmt.Errorf("failed to update params message: %v (output: %s)", err, string(output)))
31253125
}
31263126
}
31273127

service/launchd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (j *Launchd) Create(binaryVersion, appHome string) error {
7272
cmd := exec.Command("tee", plistPath)
7373
template := DarwinTemplateMap[j.commandName]
7474
cmd.Stdin = strings.NewReader(fmt.Sprintf(string(template), binaryName, binaryPath, appHome, userHome, weaveLogPath, j.GetCommandName()))
75-
if err := cmd.Run(); err != nil {
76-
return fmt.Errorf("failed to create service: %v", err)
75+
if output, err := cmd.CombinedOutput(); err != nil {
76+
return fmt.Errorf("failed to create service: %v (output: %s)", err, string(output))
7777
}
7878
return j.reloadService()
7979
}
@@ -102,8 +102,8 @@ func (j *Launchd) reloadService() error {
102102
unloadCmd := exec.Command("launchctl", "unload", filepath.Join(userHome, launchdServiceFilePath, fmt.Sprintf("%s.plist", serviceName)))
103103
_ = unloadCmd.Run()
104104
loadCmd := exec.Command("launchctl", "load", filepath.Join(userHome, launchdServiceFilePath, fmt.Sprintf("%s.plist", serviceName)))
105-
if err := loadCmd.Run(); err != nil {
106-
return fmt.Errorf("failed to load service: %v", err)
105+
if output, err := loadCmd.CombinedOutput(); err != nil {
106+
return fmt.Errorf("failed to load service: %v (output: %s)", err, string(output))
107107
}
108108
return nil
109109
}

service/systemd.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ func (j *Systemd) ensureUserServicePrerequisites() error {
5151
}
5252

5353
enableCmd := exec.Command("loginctl", "enable-linger", j.user.Username)
54-
if err := enableCmd.Run(); err != nil {
55-
return fmt.Errorf("failed to enable lingering. Please run 'loginctl enable-linger %s' manually: %v",
56-
j.user.Username, err)
54+
if output, err := enableCmd.CombinedOutput(); err != nil {
55+
return fmt.Errorf("failed to enable lingering. Please run 'loginctl enable-linger %s' manually: %v (output: %s)",
56+
j.user.Username, err, string(output))
5757
}
5858

5959
// Check and set XDG_RUNTIME_DIR if not set
@@ -168,7 +168,12 @@ func (j *Systemd) systemctl(args ...string) error {
168168
} else {
169169
cmd = exec.Command("systemctl", args...)
170170
}
171-
return cmd.Run()
171+
172+
// Capture both stdout and stderr
173+
if output, err := cmd.CombinedOutput(); err != nil {
174+
return fmt.Errorf("systemctl error: %v, output: %s", err, string(output))
175+
}
176+
return nil
172177
}
173178

174179
func (j *Systemd) getServiceDirPath() string {

0 commit comments

Comments
 (0)