internal/warpc: Improve the JS plugin API

* Move the error handling into commons and make sure the error returned also returns message errors
* Make the protocol version an int so it can be more easily compared
This commit is contained in:
Bjørn Erik Pedersen
2024-09-12 09:13:47 +02:00
parent fe7e137e28
commit 28f621d4a7
9 changed files with 68 additions and 43 deletions

View File

@@ -235,7 +235,7 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (types.Result[temp
_, r, err := fileCache.GetOrCreate(key, func() (io.ReadCloser, error) {
message := warpc.Message[warpc.KatexInput]{
Header: warpc.Header{
Version: "v1",
Version: 1,
ID: ns.id.Add(1),
},
Data: katexInput,
@@ -249,9 +249,6 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (types.Result[temp
if err != nil {
return nil, err
}
if result.Header.Err != "" {
return nil, errors.New(result.Header.Err)
}
return hugio.NewReadSeekerNoOpCloserFromString(result.Data.Output), nil
})
if err != nil {