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

Return error for multiple config options set #854

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

Diogenesoftoronto
Copy link
Contributor

An error is now returned when a more than one storage configuration has
been set. Previously, this would not return an error and simply use what
-ever the user had set that was first in the storage switch options.

Closes #853

@Diogenesoftoronto Diogenesoftoronto force-pushed the dev/issue-853-return-error-when-multiple-config branch from 493aa41 to e2c2a6b Compare February 2, 2024 19:08
Copy link
Contributor

@sevein sevein left a comment

Choose a reason for hiding this comment

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

You forgot to add a test, I wrote one and it confirmed that your solution isn't working. See f9ba7a3 where I've added a different kind of check early in the function.

case types.S3 != nil:
c.Value = types.S3
case types.SFTPConfig != nil:
if reflect.ValueOf(c.Value).IsValid() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we can still use a simple nil check here, right? If you disagree please show me what's the value added because I can't see it. This could be a starting point for us to understand it: https://go.dev/play/p/y2XQtTZ1jnQ.

@Diogenesoftoronto
Copy link
Contributor Author

I expected this to work because I expected Cstyle switch statements. I this works if I write the fall through keywords then we don't need to unMarshall a struct and allocate any extra memory here.

@sevein sevein force-pushed the dev/issue-853-return-error-when-multiple-config branch from f9ba7a3 to 299fbc6 Compare February 6, 2024 10:00
An error is now returned when the configuration document provides multiple
storage configuration values.

Co-authored-by: Jesús García Crespo <[email protected]>
@sevein sevein force-pushed the dev/issue-853-return-error-when-multiple-config branch from 299fbc6 to f485022 Compare February 6, 2024 10:06
@sevein
Copy link
Contributor

sevein commented Feb 6, 2024

I this works if I write the fall through keywords then we don't need to unMarshall a struct and allocate any extra memory here.

I'd love to see what that looks like. Feel free to push a new commit with changes to UnmarshalJSON, ensuring the tests still pass.

@sevein
Copy link
Contributor

sevein commented Feb 8, 2024

Going to merge, feel free to submit an additional PR showing your alternative to UnmarshalJSON if you feel like it. I personally feel like this is easy to read and the overhead is definitely not substantial.

@sevein sevein merged commit f75db1b into main Feb 8, 2024
11 checks passed
@sevein sevein deleted the dev/issue-853-return-error-when-multiple-config branch February 8, 2024 11:51
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.

Problem: Current storage configuration allows for mutually exclusive options to be chosen
2 participants