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

fix: fail silently for unsupported actions #2

Merged
merged 2 commits into from
Jul 30, 2024
Merged

Conversation

jamestelfer
Copy link
Owner

@jamestelfer jamestelfer commented Jul 30, 2024

Credential storage makes little sense for a plugin based on environment variables.

Failure to store or delete is written as a warning, but will not fail the Docker process.

Summary by CodeRabbit

  • New Features

    • Enhanced credential retrieval logic to conditionally handle errors based on a new optional credentials setting.
    • Updated logging for adding and deleting credentials to provide clearer warnings about unsupported functionalities.
  • Bug Fixes

    • Refined test cases to reflect the expected silent failure behaviour for add and delete functions, ensuring no errors are raised.

Credential storage makes little sense for a plugin based on environment variables.

Failure to store or delete is written as a warning, but will not fail the Docker process.
Copy link

coderabbitai bot commented Jul 30, 2024

Walkthrough

The recent updates to the EnvHelper methods in helper/env.go enhance logging and modify return values for the Add and Delete functions. These methods now log warnings and return nil instead of errors, signifying successful execution despite their unimplemented status. The corresponding tests were adjusted to align with this new behaviour, highlighting expectations of silent failures for certain operations.

Changes

File Change Summary
helper/env.go Enhanced Get, Add, and Delete methods with new logging behaviour and revised return values; Get now handles credential retrieval conditionally.
helper/env_test.go Renamed test functions to reflect silent failure expectations; assertions modified to expect no errors for Add and Delete, while List checks for errors remain.
main.go Updated credentials.Serve to use CredentialsOptional from an environment variable, altering credential handling based on configuration.

Poem

🐰 In the warren where changes play,
The helpers now work in a different way.
No more errors, just warnings bright,
Silent success brings pure delight!
Hopping along, we cheer and sing,
For every change, a new spring! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 75.92%. Comparing base (8b6b6cb) to head (e1a3945).

Files Patch % Lines
main.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
+ Coverage   74.46%   75.92%   +1.45%     
==========================================
  Files           2        2              
  Lines          47       54       +7     
==========================================
+ Hits           35       41       +6     
- Misses         12       13       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b6b6cb and 802272d.

Files selected for processing (2)
  • helper/env.go (1 hunks)
  • helper/env_test.go (1 hunks)
Additional comments not posted (5)
helper/env.go (2)

36-37: LGTM! The function correctly fails silently for unsupported actions.

The Add function now logs a warning and returns nil, which aligns with the PR objective.


41-42: LGTM! The function correctly fails silently for unsupported actions.

The Delete function now logs a warning and returns nil, which aligns with the PR objective.

helper/env_test.go (3)

34-37: LGTM! The test correctly checks that the Add method fails silently.

The test function TestEnvHelper_Add_FailsSilently asserts no error is returned, which aligns with the new behaviour.


40-43: LGTM! The test correctly checks that the Delete method fails silently.

The test function TestEnvHelper_Delete_FailsSilently asserts no error is returned, which aligns with the new behaviour.


46-48: LGTM! The test correctly checks that the List method is not implemented.

The test function TestEnvHelper_List_NotImplemented asserts an error is returned, which aligns with the behaviour.

Allow the user to configure the helper such that failure to find the required environment variables results in an empty username and password being returned instead of causing the helper to fail.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 802272d and e1a3945.

Files selected for processing (3)
  • helper/env.go (1 hunks)
  • helper/env_test.go (2 hunks)
  • main.go (1 hunks)
Additional context used
GitHub Check: codecov/patch
main.go

[warning] 24-24: main.go#L24
Added line #L24 was not covered by tests


[warning] 26-26: main.go#L26
Added line #L26 was not covered by tests

Additional comments not posted (13)
helper/env.go (7)

22-22: LGTM!

The new field CredentialsOptional in the EnvHelper struct is a good addition to control the behaviour of credential operations.


32-36: LGTM!

The conditional logic in the Get function to handle credential lookup failures based on CredentialsOptional improves flexibility.


38-39: LGTM!

The error logging behaviour in the Get function ensures that users are informed about potential issues when CredentialsOptional is false.


42-42: LGTM!

Logging a message when credentials are successfully retrieved is useful for confirming successful operations.


48-48: LGTM!

The Add function now logs a warning and returns nil, aligning with the new behaviour of failing silently for unsupported actions.


53-54: LGTM!

The Delete function now logs a warning and returns nil, aligning with the new behaviour of failing silently for unsupported actions.


58-58: LGTM!

The List function logs an error message and returns ErrNotImplemented, maintaining the appropriate behaviour for an unimplemented action.

helper/env_test.go (6)

24-33: LGTM!

The new test function TestEnvHelper_Get_CredentialsOptional_Success verifies the behaviour of the Get function when CredentialsOptional is true. This is a necessary test to ensure the new functionality works as expected.


45-45: LGTM!

Renaming the test function to TestEnvHelper_Add_FailsSilently clarifies the expected behaviour of the Add function, improving test readability.


48-48: LGTM!

The modified assertion in the TestEnvHelper_Add_FailsSilently function aligns with the new behaviour of the Add function, which is to fail silently.


51-51: LGTM!

Renaming the test function to TestEnvHelper_Delete_FailsSilently clarifies the expected behaviour of the Delete function, improving test readability.


54-54: LGTM!

The modified assertion in the TestEnvHelper_Delete_FailsSilently function aligns with the new behaviour of the Delete function, which is to fail silently.


57-57: LGTM!

Renaming the test function to TestEnvHelper_List_NotImplemented clarifies the expected behaviour of the List function, improving test readability.

main.go Show resolved Hide resolved
main.go Show resolved Hide resolved
@jamestelfer jamestelfer merged commit 5fc75ee into main Jul 30, 2024
5 checks passed
@jamestelfer jamestelfer deleted the failure-mode-fix branch July 30, 2024 13:44
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.

1 participant