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

Run built-in plugins before others #1277

Closed
gosar opened this issue Jun 15, 2022 · 4 comments
Closed

Run built-in plugins before others #1277

gosar opened this issue Jun 15, 2022 · 4 comments
Labels
feature-request A feature should be added or improved.

Comments

@gosar
Copy link
Contributor

gosar commented Jun 15, 2022

When smithy build fails on a plugin that is not built-in (i.e., not model, build-info or sources), even though I think the model itself is good, depending on the order of plugins, the model plugin may not have been run yet. Having the model plugin run before would allow seeing the full model serialized even when other plugins fail.

I found that the plugins end up in a TreeMap here making it natural order. It uses LinkedHashMap in the SmithyBuildConfig here, so it seems if we use LinkedHashMap instead of TreeMap in SmithyBuildImpl, we could make sure the BUILTIN_PLUGINS always get run first.

@milesziemer
Copy link
Contributor

It looks like BUILTIN_PLUGINS are added right before SmithyBuildConfig is built here, so the built-in plugins are always after any other plugins present in SmithyBuildConfig. I think we would need a combination of using LinkedHashMap in SmithyBuildImpl, and some way to make sure that BUILTIN_PLUGINS come before any other plugins when SmithyBuildConfig is built.

As this comment says, we can't add BUILTIN_PLUGINS before this point because they could be removed when plugins() is called. Plugins can also be set when a config file is loaded.

I guess a solution could be to just use a temporary Map to reverse the ordering.

@mtdowling
Copy link
Member

Would it be possible to instead not fail the whole build if one plugin fails, and defer the failure until the end?

@milesziemer milesziemer added the feature-request A feature should be added or improved. label Sep 13, 2022
@milesziemer
Copy link
Contributor

milesziemer commented Sep 16, 2022

I've been looking into deferring the failure until the end a bit more. When a plugin fails, the error is caught here in SmithyBuildImpl, and is passed on to the exception consumer. The plugins are applied in a loop when running the projection, so we could catch and aggregate any errors within that loop to allow the rest of the plugins to run. The projection still needs to fail, so I think a solution would be to use the individual plugin errors to create one big projection error, then throw that after all the plugins have run.

I think a better solution might involve some refactoring of how SmithyBuildImpl works, as it is a bit messy, especially if we intend on changing how projections run (see this comment). I couldn't think of any obvious way to refactor it, but for now I don't see this change adding too much complexity so I can get a PR up for it if that sounds good, unless I'm missing something.

@kstich
Copy link
Contributor

kstich commented Jul 19, 2023

This was resolved in #1762 , running all plugins for a projection before failure.

@kstich kstich closed this as completed Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

4 participants