Skip to content

Commit 6037aa5

Browse files
authored
Merge pull request #308 from bytecodealliance/ydnar/wasm-tools-errors
wit, wit/bindgen: improve wasm-tools error reporting
2 parents 27486dd + f17a23b commit 6037aa5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

wit/bindgen/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ func (g *generator) newPackage(w *wit.World, i *wit.Interface, name string) (*ge
23872387
}
23882388
content, err := g.componentEmbed(witText)
23892389
if err != nil {
2390-
g.opts.logger.Errorf("WIT:\n%s\n\n", witText)
2390+
g.opts.logger.Errorf("Generated WIT for custom section:\n%s\n\n", witText)
23912391
return nil, err
23922392
}
23932393
componentType := &wasm.CustomSection{

wit/load.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"io/fs"
1010
"os"
1111
"path/filepath"
12+
"strings"
1213

14+
"github.com/tetratelabs/wazero/sys"
1315
"go.bytecodealliance.org/internal/wasmtools"
1416
)
1517

@@ -58,6 +60,7 @@ func loadWIT(path string, reader io.Reader) (*Resolve, error) {
5860
var stdin io.Reader
5961

6062
if path != "" {
63+
path = strings.TrimPrefix(path, "./")
6164
args = append(args, path)
6265
dir := filepath.Dir(path)
6366
fsMap[dir] = os.DirFS(dir)
@@ -69,9 +72,13 @@ func loadWIT(path string, reader io.Reader) (*Resolve, error) {
6972
return nil, err
7073
}
7174
stdout := &bytes.Buffer{}
72-
err = wasmTools.Run(ctx, stdin, stdout, nil, fsMap, args...)
75+
stderr := &bytes.Buffer{}
76+
err = wasmTools.Run(ctx, stdin, stdout, stderr, fsMap, args...)
7377
if err != nil {
74-
return nil, fmt.Errorf("error executing wasm-tools: %w", err)
78+
if _, ok := err.(*sys.ExitError); ok {
79+
return nil, fmt.Errorf("wasm-tools: %s", stderr.String())
80+
}
81+
return nil, fmt.Errorf("wasm-tools: %w", err)
7582
}
7683
return DecodeJSON(stdout)
7784
}

0 commit comments

Comments
 (0)