Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and document CLI error handling #5700

Merged
merged 1 commit into from
Jun 17, 2023
Merged

Simplify and document CLI error handling #5700

merged 1 commit into from
Jun 17, 2023

Conversation

rynowak
Copy link
Contributor

@rynowak rynowak commented Jun 12, 2023

Description

This change turns the FriendlyError type into an interface and adds convenience functionality for creating user-facing errors. This allows us more flexibility for packages to define their own types of errors that are handled gracefully by the CLI - for example the console interrupt in the prompt package no longer needs special handling.

Additionally I documented our existing practices for user-facing errors in the development documentation and did a consistency pass of ALL of the existing error messages I could find.

Auto-generated summary

🤖 Generated by Copilot at 77895a7

Summary

📝🐛🚀

This pull request introduces a new clierrors package for creating and handling user-friendly error messages in the rad CLI. It refactors the existing code in the cmd and cli packages to use the new package and simplifies the error handling logic. It also updates the documentation for contributing code and running tests for the CLI.

clierrors package
enhances CLI error messages
friendly and clear

Walkthrough

  • Introduce the clierrors package to define and create user-friendly error types and messages for the CLI (link, link, link)
  • Replace the use of the cli.FriendlyError type with the clierrors.Message or clierrors.MessageWithCause functions, which simplify the error creation and formatting logic (link, link, link, link, link, link, link, link, link, link, link)
  • Replace the use of the errors.Is function with the direct comparison of the error type or the clierrors.IsFriendlyError function, which improve the error checking logic (link, link, link, link)
  • Remove unused imports of the errors, fmt, and cli packages from various files (link, link, link, link, link, link, link, link, link)
  • Add the clierrors package to various files that use the friendly error types or functions (link, link, link, link, link, link, link, link, link, link, link)
  • Remove unnecessary use of the cli.FriendlyError type for errors that already implement the clierrors.FriendlyError interface (link)
  • Improve some error messages by adding or removing information (link, link, link)
  • Add and update documentation for contributing code to the CLI, writing code for the CLI, and running functional tests (link, link, link, link, link, link)

@rynowak rynowak requested a review from a team as a code owner June 12, 2023 01:51
@github-actions
Copy link

github-actions bot commented Jun 12, 2023

Radius functional test overview

🔍 Go to test action run

Name Value
Repository project-radius/radius
Commit ref 77895a7
Unique ID dbe24a14fa
Image tag pr-dbe24a14fa
Click here to see the list of tools in the current test run
  • gotestsum 1.10.0
  • KinD: v0.18.0
  • Dapr: 1.10.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.0.0
  • recipe location radiusdev.azurecr.io/test/functional/corerp/recipes/<name>:pr-dbe24a14fa
  • appcore-rp test image location: radiusdev.azurecr.io/appcore-rp:pr-dbe24a14fa
  • ucp test image location: radiusdev.azurecr.io/ucpd:pr-dbe24a14fa

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp functional tests...
⌛ Starting samples functional tests...
✅ samples functional tests succeeded
⌛ Starting ucp functional tests...
✅ ucp functional tests succeeded
✅ corerp functional tests succeeded

@github-actions
Copy link

github-actions bot commented Jun 12, 2023

Test Results

2 736 tests  +67   2 729 ✔️ +71   1m 59s ⏱️ -3s
   245 suites +  1          7 💤 ±  0 
       1 files   ±  0          0  -   4 

Results for commit a3870bf. ± Comparison against base commit 76114cf.

This pull request removes 2 and adds 69 tests. Note that renamed tests count towards both.
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/4688b318-b3ba-4c9d-878b-95f6e54bd5cd
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/4688b318-b3ba-4c9d-878b-95f6e54bd5cd#01
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/0153ec62-3e48-4294-91c3-2c9bb38e5b60
github.com/project-radius/radius/pkg/armrpc/frontend/controller ‑ TestValidateEtag_IfMatch/0153ec62-3e48-4294-91c3-2c9bb38e5b60#01
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_CommandValidation
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init_--dev`_w/o_recipes
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init_--dev`_with_AWS_Provider
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init_--dev`_with_no_providers
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init_--dev`_with_recipes
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init`_with_AWS_Provider
github.com/project-radius/radius/pkg/cli/cmd/radinit ‑ Test_Run_InstallAndCreateEnvironment/`rad_init`_with_Azure_Provider
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link

63.6

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 63.6 %
  • main branch coverage: 63.5 %
  • diff coverage: .1 %

The coverage result does not include the functional test coverage.

Copy link
Contributor

@willdavsmith willdavsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

cmd/rad/cmd/debuglogs.go Show resolved Hide resolved
cmd/rad/cmd/resourceExpose.go Outdated Show resolved Hide resolved
pkg/cli/cmd/radinit/cluster.go Outdated Show resolved Hide resolved
pkg/cli/cmd/radinit/cluster.go Outdated Show resolved Hide resolved
pkg/cli/cmd/recipe/register/register.go Outdated Show resolved Hide resolved
@@ -61,7 +61,7 @@ func (i *impl) CreateDeploymentClient(ctx context.Context, workspace workspaces.

err = sdk.TestConnection(ctx, connection)
if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) {
return nil, &cli.FriendlyError{Message: err.Error()}
return nil, clierrors.MessageWithCause(err, "could not connect to Radius")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, clierrors.MessageWithCause(err, "could not connect to Radius")
return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.")

pkg/cli/connections/factory.go Outdated Show resolved Hide resolved
This change turns the `FriendlyError` type into an interface and adds convenience functionality for creating user-facing errors. This allows us more flexibility for packages to define their own types of errors that are handled gracefully by the CLI - for example the console interrupt in the prompt package no longer needs special handling.

Additionally I documented our existing practices for user-facing errors in the development documentation and did a consistency pass of ALL of the existing error messages I could find.
@github-actions
Copy link

github-actions bot commented Jun 17, 2023

Radius functional test overview

🔍 Go to test action run

Name Value
Repository project-radius/radius
Commit ref a3870bf
Unique ID 593154baa0
Image tag pr-593154baa0
Click here to see the list of tools in the current test run
  • gotestsum 1.10.0
  • KinD: v0.18.0
  • Dapr: 1.10.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.0.0
  • recipe location radiusdev.azurecr.io/test/functional/corerp/recipes/<name>:pr-593154baa0
  • appcore-rp test image location: radiusdev.azurecr.io/appcore-rp:pr-593154baa0
  • ucp test image location: radiusdev.azurecr.io/ucpd:pr-593154baa0

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting ucp functional tests...
⌛ Starting samples functional tests...
⌛ Starting corerp functional tests...
✅ samples functional tests succeeded
✅ ucp functional tests succeeded
✅ corerp functional tests succeeded

@github-actions
Copy link

64.4

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 64.4 %
  • main branch coverage: 64.0 %
  • diff coverage: .4 %

The coverage result does not include the functional test coverage.

@rynowak rynowak merged commit 491c638 into main Jun 17, 2023
@rynowak rynowak deleted the rynowak/clierrors branch June 17, 2023 21:05
nithyatsu pushed a commit that referenced this pull request Jun 21, 2023
# Description

This change turns the `FriendlyError` type into an interface and adds
convenience functionality for creating user-facing errors. This allows
us more flexibility for packages to define their own types of errors
that are handled gracefully by the CLI - for example the console
interrupt in the prompt package no longer needs special handling.

Additionally I documented our existing practices for user-facing errors
in the development documentation and did a consistency pass of ALL of
the existing error messages I could find.

## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 77895a7</samp>

### Summary
📝🐛🚀

<!--
1. 📝 - This emoji represents the changes that add or improve
documentation for the CLI, such as the new section for error handling
guidelines, the instructions for testing and debugging, and the warning
for functional tests.
2. 🐛 - This emoji represents the changes that fix or enhance the error
handling and messaging in the CLI, such as the use of the clierrors
package, the simplification of the error checking logic, and the removal
of redundant code.
3. 🚀 - This emoji represents the changes that improve the user
experience and performance of the CLI, such as the more consistent and
informative error messages, the credential validation, and the aws
package.
-->
This pull request introduces a new `clierrors` package for creating and
handling user-friendly error messages in the `rad` CLI. It refactors the
existing code in the `cmd` and `cli` packages to use the new package and
simplifies the error handling logic. It also updates the documentation
for contributing code and running tests for the CLI.

> _`clierrors` package_
> _enhances CLI error messages_
> _friendly and clear_

### Walkthrough
* Introduce the `clierrors` package to define and create user-friendly
error types and messages for the CLI
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-63404f70ef0aebce10d585c4f666381cb466470798b0eb5f7a1573318e542819R1-R31),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-c59fbc84834d0c8744895c1743d50ad3b52585c5b966c6e44fb6953c7ec7fd42R1-R35),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2f6b9e0c158058ace98b7beafd108285fd9648eff08b80d822afbf9ea24cb645R1-R56))
* Replace the use of the `cli.FriendlyError` type with the
`clierrors.Message` or `clierrors.MessageWithCause` functions, which
simplify the error creation and formatting logic
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-3abc8210264132b6c7c39842e1f0e9cfc67d8bcffc0dc82370261d4a83005a71L65-R66),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-eb1fb0acb333d81cd98eb18a726c7a9c218a7fc40b41fe09c698b3a9e1f36085L76-R96),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9L439-R440),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-298b3426311d1616260c81704588becbb63bafaeca245d9b8480b53b684a6708L102-R102),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-e81cb9ae5d8b783a0b674004a2df20c8faba1adf9585f4d028615c205e40e40cL123-R123),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2b3a46be3fab0d68fc258c962cf6ce1621b93ca7667fb4239a2ba6e0d1ec3308L124-R124),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL121-R123),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL134-R133),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL152-R151),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-65dd9b06f95ecad5a7ed9bd20d23ab719dc556133f5ca13c33f0ed99dd06cb09L45-R44),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-8515ea5f77ea63b91103fb2b1b17d23fdc76cd50ecbbe1552ce1274497ac4290L119-R127))
* Replace the use of the `errors.Is` function with the direct comparison
of the error type or the `clierrors.IsFriendlyError` function, which
improve the error checking logic
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-d36b7b4d04f01a6cf60c50dd9c01da8fb8c190231ea4c59cbbfbe070178b510bL146-R153),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-0d19f5b0c83b43f0f60b644a588f32e118296e1c8232e239d3dcc164c53d8f0bL291-R290),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-cea48b3105483f1a27bcc32c7c0ad99f4f5e68040aef470abe48e024d96ba646L168-R168),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-d3a3459434e925881f5cd87077b6f7db62ff30d190094cb46a71d632a71fe32dL228-R228))
* Remove unused imports of the `errors`, `fmt`, and `cli` packages from
various files
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-d36b7b4d04f01a6cf60c50dd9c01da8fb8c190231ea4c59cbbfbe070178b510bL22),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9R25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-87907dd86f66c5e0992fef2ea8d8bc09cf79e4cf4e6d9108cb137a536da03c10L21),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-0d19f5b0c83b43f0f60b644a588f32e118296e1c8232e239d3dcc164c53d8f0bL25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-cea48b3105483f1a27bcc32c7c0ad99f4f5e68040aef470abe48e024d96ba646L24-R25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-d3a3459434e925881f5cd87077b6f7db62ff30d190094cb46a71d632a71fe32dL24-R26),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL27-R28),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-65dd9b06f95ecad5a7ed9bd20d23ab719dc556133f5ca13c33f0ed99dd06cb09L20-R24),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-8515ea5f77ea63b91103fb2b1b17d23fdc76cd50ecbbe1552ce1274497ac4290L21-R24))
* Add the `clierrors` package to various files that use the friendly
error types or functions
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-3abc8210264132b6c7c39842e1f0e9cfc67d8bcffc0dc82370261d4a83005a71R28),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-eb1fb0acb333d81cd98eb18a726c7a9c218a7fc40b41fe09c698b3a9e1f36085R27),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-d36b7b4d04f01a6cf60c50dd9c01da8fb8c190231ea4c59cbbfbe070178b510bR31),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9R25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-298b3426311d1616260c81704588becbb63bafaeca245d9b8480b53b684a6708L21-R25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-e81cb9ae5d8b783a0b674004a2df20c8faba1adf9585f4d028615c205e40e40cL21-R24),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-cea48b3105483f1a27bcc32c7c0ad99f4f5e68040aef470abe48e024d96ba646L24-R25),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2b3a46be3fab0d68fc258c962cf6ce1621b93ca7667fb4239a2ba6e0d1ec3308L21-R24),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL27-R28),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-65dd9b06f95ecad5a7ed9bd20d23ab719dc556133f5ca13c33f0ed99dd06cb09L20-R24),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-8515ea5f77ea63b91103fb2b1b17d23fdc76cd50ecbbe1552ce1274497ac4290L21-R24))
* Remove unnecessary use of the `cli.FriendlyError` type for errors that
already implement the `clierrors.FriendlyError` interface
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-87907dd86f66c5e0992fef2ea8d8bc09cf79e4cf4e6d9108cb137a536da03c10L128-L130))
* Improve some error messages by adding or removing information
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-65dd9b06f95ecad5a7ed9bd20d23ab719dc556133f5ca13c33f0ed99dd06cb09L45-R44),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL134-R133),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-52020886a399cc0113d50174c1beafe22429f71d4a740d10b8be819659eee8fcL152-R151))
* Add and update documentation for contributing code to the CLI, writing
code for the CLI, and running functional tests
([link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2dc9993002cdaecc3a50b94159e9a38375dac771eb42557306649c0a4883002bR7-R10),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2dc9993002cdaecc3a50b94159e9a38375dac771eb42557306649c0a4883002bL69-R75),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-2dc9993002cdaecc3a50b94159e9a38375dac771eb42557306649c0a4883002bL78-R107),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-e286d51f1368685af6439c0bd568dc2cbee5c7c3806112b211a8844754c0b1c6R49-R50),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-e286d51f1368685af6439c0bd568dc2cbee5c7c3806112b211a8844754c0b1c6R86-R99),
[link](https://github.com/project-radius/radius/pull/5700/files?diff=unified&w=0#diff-19c6617fdff9355dc160bf265e7efdc44ac178e0a5257bd6bd96a22dd56f1883R52-R89))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants