Skip to content

Update Cobra sub commands to use RunE#254

Merged
dvaumoron merged 1 commit intotofuutils:mainfrom
diebietse:feature/ExitNonZeroOneError
Sep 28, 2024
Merged

Update Cobra sub commands to use RunE#254
dvaumoron merged 1 commit intotofuutils:mainfrom
diebietse:feature/ExitNonZeroOneError

Conversation

@ncthompson
Copy link
Copy Markdown
Contributor

We have a use case where we pre-install terraform and terragrunt versions for pipeline usage, to ensure we don't get rate limited. The problem is, that if the installation fails, it does not fail the build process. This is because tenv always exists with status 0.

You can simulate this with

tenv tf install v5000
Installing Terraform 5000.0.0
Fetching release information from https://releases.hashicorp.com/terraform/5000.0.0/index.json
unexpected value returned by API
echo $?
0

This change makes use of Cobra's RunE command instead of just the Run command for all sub command calls. This will allow any error event in the run command to cause tenv to exit with a non zero value. This is useful to detect install and update failures in scripts.

Sample output with the change implemented:

go run ./cmd/tenv tf install v5000
Installing Terraform 5000.0.0
Fetching release information from https://releases.hashicorp.com/terraform/5000.0.0/index.json
unexpected value returned by API
Error: unexpected value returned by API
unexpected value returned by API
exit status 1
echo $?
1

Update all the sub command to make use of the RunE function call. This will allow any error event in the run command to cause tenv to exit with a non zero value. This is useful to detect install and update failures in scripts.

Signed-off-by: Nicholas Thompson <github@hoekwil.com>
@kvendingoldo
Copy link
Copy Markdown
Collaborator

Agree, it can be really useful.

@kvendingoldo kvendingoldo added the enhancement New feature or request label Sep 27, 2024
@dvaumoron dvaumoron merged commit 1e081be into tofuutils:main Sep 28, 2024
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 11, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [tofuutils/tenv](https://github.com/tofuutils/tenv) | minor | `v3.1.0` -> `v3.2.4` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>tofuutils/tenv (tofuutils/tenv)</summary>

### [`v3.2.4`](https://github.com/tofuutils/tenv/releases/tag/v3.2.4)

[Compare Source](tofuutils/tenv@v3.2.3...v3.2.4)

#### What's Changed

-   docs: add Oh My Zsh completion by [@&#8203;samuel-phan](https://github.com/samuel-phan) in tofuutils/tenv#258
-   Fix : proxy missing env by [@&#8203;dvaumoron](https://github.com/dvaumoron) in tofuutils/tenv#260

#### New Contributors

-   [@&#8203;samuel-phan](https://github.com/samuel-phan) made their first contribution in tofuutils/tenv#258

**Full Changelog**: tofuutils/tenv@v3.2.3...v3.2.4

### [`v3.2.3`](https://github.com/tofuutils/tenv/releases/tag/v3.2.3)

[Compare Source](tofuutils/tenv@v3.2.2...v3.2.3)

#### What's Changed

-   go: bump github.com/charmbracelet/bubbletea from 1.1.0 to 1.1.1 by [@&#8203;dependabot](https://github.com/dependabot) in tofuutils/tenv#251
-   Update Cobra sub commands to use RunE by [@&#8203;ncthompson](https://github.com/ncthompson) in tofuutils/tenv#254
-   Avoid duplicate error message display  by [@&#8203;dvaumoron](https://github.com/dvaumoron) in tofuutils/tenv#256

#### New Contributors

-   [@&#8203;ncthompson](https://github.com/ncthompson) made their first contribution in tofuutils/tenv#254

**Full Changelog**: tofuutils/tenv@v3.2.2...v3.2.3

### [`v3.2.2`](https://github.com/tofuutils/tenv/releases/tag/v3.2.2)

[Compare Source](tofuutils/tenv@v3.2.1...v3.2.2)

#### What's Changed

-   Fix : read iac files from WorkPath (chdir proxy flag) by [@&#8203;dvaumoron](https://github.com/dvaumoron) in tofuutils/tenv#250

**Full Changelog**: tofuutils/tenv@v3.2.1...v3.2.2

### [`v3.2.1`](https://github.com/tofuutils/tenv/releases/tag/v3.2.1)

[Compare Source](tofuutils/tenv@v3.1.0...v3.2.1)

#### What's Changed

-   fix : skip all cosign tests by [@&#8203;dvaumoron](https://github.com/dvaumoron) in tofuutils/tenv#248

**Full Changelog**: tofuutils/tenv@v3.2.0...v3.2.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants