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: init app client API chainer only when chain info is available #3963

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes

- [#3953](https://github.com/ignite/cli/pull/3953) Fix apps `Stdout` is redirected to `Stderr`
- [#3863](https://github.com/ignite/cli/pull/3963) Fix breaking issue for app client API when reading app chain info

## [`v28.2.0`](https://github.com/ignite/cli/releases/tag/v28.2.0)

Expand Down
45 changes: 28 additions & 17 deletions ignite/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@
}
}

// Get chain when the plugin runs inside an blockchain app
c, err := newChainWithHomeFlags(cmd)
if err != nil && !errors.Is(err, gomodule.ErrGoModNotFound) {
api, err := newAppClientAPI(cmd)
if err != nil {
return err
}

ctx := cmd.Context()
execHook := newExecutedHook(hook, cmd, args)
err = p.Interface.ExecuteHookPre(ctx, execHook, plugin.NewClientAPI(plugin.WithChain(c)))
err = p.Interface.ExecuteHookPre(ctx, execHook, api)
if err != nil {
return errors.Errorf("app %q ExecuteHookPre() error: %w", p.Path, err)
}
Expand All @@ -224,15 +223,14 @@
err := runCmd(cmd, args)
// if the command has failed the `PostRun` will not execute. here we execute the cleanup step before returnning.
if err != nil {
// Get chain when the plugin runs inside an blockchain app
c, err := newChainWithHomeFlags(cmd)
if err != nil && !errors.Is(err, gomodule.ErrGoModNotFound) {
api, err := newAppClientAPI(cmd)
if err != nil {

Check warning on line 227 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L226-L227

Added lines #L226 - L227 were not covered by tests
return err
}

ctx := cmd.Context()
execHook := newExecutedHook(hook, cmd, args)
err = p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewClientAPI(plugin.WithChain(c)))
err = p.Interface.ExecuteHookCleanUp(ctx, execHook, api)

Check warning on line 233 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L233

Added line #L233 was not covered by tests
if err != nil {
cmd.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err)
}
Expand All @@ -246,17 +244,16 @@

postCmd := cmd.PostRunE
cmd.PostRunE = func(cmd *cobra.Command, args []string) error {
// Get chain when the plugin runs inside an blockchain app
c, err := newChainWithHomeFlags(cmd)
if err != nil && !errors.Is(err, gomodule.ErrGoModNotFound) {
api, err := newAppClientAPI(cmd)
if err != nil {
return err
}

ctx := cmd.Context()
execHook := newExecutedHook(hook, cmd, args)

defer func() {
err := p.Interface.ExecuteHookCleanUp(ctx, execHook, plugin.NewClientAPI(plugin.WithChain(c)))
err := p.Interface.ExecuteHookCleanUp(ctx, execHook, api)
if err != nil {
cmd.Printf("app %q ExecuteHookCleanUp() error: %v", p.Path, err)
}
Expand All @@ -270,7 +267,7 @@
}
}

err = p.Interface.ExecuteHookPost(ctx, execHook, plugin.NewClientAPI(plugin.WithChain(c)))
err = p.Interface.ExecuteHookPost(ctx, execHook, api)
if err != nil {
return errors.Errorf("app %q ExecuteHookPost() error : %w", p.Path, err)
}
Expand Down Expand Up @@ -333,9 +330,8 @@
newCmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
return clictx.Do(ctx, func() error {
// Get chain when the plugin runs inside an blockchain app
c, err := newChainWithHomeFlags(cmd)
if err != nil && !errors.Is(err, gomodule.ErrGoModNotFound) {
api, err := newAppClientAPI(cmd)
if err != nil {
return err
}

Expand All @@ -348,7 +344,7 @@
With: p.With,
}
execCmd.ImportFlags(cmd)
err = p.Interface.Execute(ctx, execCmd, plugin.NewClientAPI(plugin.WithChain(c)))
err = p.Interface.Execute(ctx, execCmd, api)

// NOTE(tb): This pause gives enough time for go-plugin to sync the
// output from stdout/stderr of the plugin. Without that pause, this
Expand Down Expand Up @@ -696,6 +692,21 @@
return nil
}

func newAppClientAPI(cmd *cobra.Command) (plugin.ClientAPI, error) {
// Get chain when the plugin runs inside an blockchain app
c, err := newChainWithHomeFlags(cmd)
if err != nil && !errors.Is(err, gomodule.ErrGoModNotFound) {
return nil, err
}

Check warning on line 700 in ignite/cmd/plugin.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/plugin.go#L699-L700

Added lines #L699 - L700 were not covered by tests

var options []plugin.APIOption
if c != nil {
options = append(options, plugin.WithChain(c))
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved
}

return plugin.NewClientAPI(options...), nil
}

func flagSetPluginsGlobal() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.BoolP(flagPluginsGlobal, "g", false, "use global plugins configuration ($HOME/.ignite/apps/igniteapps.yml)")
Expand Down
Loading