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

(panic): exec mixin being passed string instead of a map causes panic #2946

Closed
schristoff opened this issue Oct 17, 2023 · 2 comments · Fixed by #2953
Closed

(panic): exec mixin being passed string instead of a map causes panic #2946

schristoff opened this issue Oct 17, 2023 · 2 comments · Fixed by #2953
Labels
bug Oops, sorry! hacktoberfest Issues chosen for Hacktoberfest 2023 help wanted Good for someone who has contributed before

Comments

@schristoff
Copy link
Member

When using the exec mixin on a bundle the following:

exec: echo hello world

Will cause a panic
however

exec:
   command: '"echo hello world"'

Will not

We should not get to the point where the former will cause a panic and we should just error

@schristoff schristoff added bug Oops, sorry! help wanted Good for someone who has contributed before hacktoberfest Issues chosen for Hacktoberfest 2023 labels Oct 17, 2023
@matheuscumpian
Copy link

Hi guys, I would like to tackle this one.

I'll come back with questions if I have, now I'm trying to learn a little bit of the project code 💌

@matheuscumpian
Copy link

matheuscumpian commented Nov 9, 2023

Hi guys, I think that the issue was in the Validate() method of the Step struct in the manifest.go file, we were trying to access a field of a map right after a type casting without check if the cast happened with success.

d, ok := children.(map[string]interface{})["description"] --> Right here
f !ok {
    return "", nil
}

I've added another step to get the description after the casting, with that we can return an error, I've just tried to use an error message that looks like the other ones, but I don´t know if it makes sense:

invalid mixin type (type) for mixin step (mixin name)

With that, when we run this invalid exec mixin:

...
install:
  - exec: "I'm a string, but I should be an object 🫠"
...

We get the following output in the install command:

$ porter install

1 error occurred:
        * validation of action "install" failed: invalid mixin type (string) for mixin step (exec)

1 error occurred:
        * validation of action "install" failed: invalid mixin type (string) for mixin step (exec)

We're "duplicating" the error logs, I tried to figure out what was happening and It seems that Cobra has a "fallback" error log in the end of a command execution that logs the error if the silence error flags is not on, so because we're logging the error in the span.Error() we see the log duplicated.

I've tried other types of error and they also duplicated the logs, but I don't know if this is expected or if I should try to handle this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Oops, sorry! hacktoberfest Issues chosen for Hacktoberfest 2023 help wanted Good for someone who has contributed before
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants