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: prevent map scaffolding from failing in an edge-case #2763

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions ignite/pkg/placeholder/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Replacer interface {
Replace(content, placeholder, replacement string) string
ReplaceAll(content, placeholder, replacement string) string
ReplaceOnce(content, placeholder, replacement string) string
ReplaceIfExists(content, placeholder, replacement string) string
AppendMiscError(miscError string)
}

Expand Down Expand Up @@ -81,6 +82,13 @@ func (t *Tracer) ReplaceOnce(content, placeholder, replacement string) string {
return content
}

func (t *Tracer) ReplaceIfExists(content, placeholder, replacement string) string {
if !strings.Contains(content, replacement) {
strings.Replace(content, placeholder, replacement, 1)
}
return content
}

// AppendMiscError allows to track errors not related to missing placeholders during file modification
func (t *Tracer) AppendMiscError(miscError string) {
t.miscErrors = append(t.miscErrors, miscError)
Expand Down
3 changes: 1 addition & 2 deletions ignite/templates/typed/map/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,9 @@ func handlerModify(replacer placeholder.Replacer, opts *typed.Options) genny.Run
if err != nil {
return err
}

// Set once the MsgServer definition if it is not defined yet
replacementMsgServer := `msgServer := keeper.NewMsgServerImpl(k)`
content := replacer.ReplaceOnce(f.String(), typed.PlaceholderHandlerMsgServer, replacementMsgServer)
content := replacer.ReplaceIfExists(f.String(), typed.PlaceholderHandlerMsgServer, replacementMsgServer)

templateHandlers := `case *types.MsgCreate%[2]v:
res, err := msgServer.Create%[2]v(sdk.WrapSDKContext(ctx), msg)
Expand Down