Skip to content

Commit

Permalink
avoid fmt.Errorf calls for an error that is never read
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Duchesneau <[email protected]>
  • Loading branch information
sduchesneau committed Dec 2, 2024
1 parent 610c202 commit 91287c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions internal/wasm/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,19 @@ func (m *ModuleInstance) applyData(data []DataSegment) error {
return nil
}

var (
ErrModuleNotExported = errors.New("module not exported")
ErrModuleWrongExternalType = errors.New("module has wrong external type")
)

// GetExport returns an export of the given name and type or errs if not exported or the wrong type.
func (m *ModuleInstance) getExport(name string, et ExternType) (*Export, error) {
exp, ok := m.Exports[name]
if !ok {
return nil, fmt.Errorf("%q is not exported in module %q", name, m.ModuleName)
return nil, ErrModuleNotExported
}
if exp.Type != et {
return nil, fmt.Errorf("export %q in module %q is a %s, not a %s", name, m.ModuleName, ExternTypeName(exp.Type), ExternTypeName(et))
return nil, ErrModuleWrongExternalType
}
return exp, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/wasm/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func Test_resolveImports(t *testing.T) {
m := &ModuleInstance{s: newStore()}
m.s.nameToModule[moduleName] = &ModuleInstance{Exports: map[string]*Export{}, ModuleName: moduleName}
err := m.resolveImports(context.Background(), &Module{ImportPerModule: map[string][]*Import{moduleName: {{Name: "unknown"}}}})
require.EqualError(t, err, "\"unknown\" is not exported in module \"test\"")
require.EqualError(t, err, ErrModuleNotExported.Error())
})
t.Run("func", func(t *testing.T) {
t.Run("ok", func(t *testing.T) {
Expand Down

0 comments on commit 91287c3

Please sign in to comment.