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

Report assembly error strings for compile API endpoint #3190

Merged
merged 4 commits into from
Nov 6, 2021
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
2 changes: 1 addition & 1 deletion cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ func assembleFile(fname string) (program []byte) {
}
ops, err := logic.AssembleString(string(text))
if err != nil {
ops.ReportProblems(fname)
ops.ReportProblems(fname, os.Stderr)
reportErrorf("%s: %s", fname, err)
}
_, params := getProto(protoVersion)
Expand Down
3 changes: 2 additions & 1 deletion cmd/goal/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -163,7 +164,7 @@ var signProgramCmd = &cobra.Command{
}
ops, err := logic.AssembleString(string(text))
if err != nil {
ops.ReportProblems(programSource)
ops.ReportProblems(programSource, os.Stderr)
reportErrorf("%s: %s", programSource, err)
}
if outname == "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/pingpong/runCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ var runCmd = &cobra.Command{
}
ops, err := logic.AssembleString(programStr)
if err != nil {
ops.ReportProblems(teal)
ops.ReportProblems(teal, os.Stderr)
reportErrorf("Internal error, cannot assemble %v \n", programStr)
}
cfg.Program = ops.Program
Expand Down
5 changes: 4 additions & 1 deletion daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"math"
"net/http"
"strings"
"time"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -754,7 +755,9 @@ func (v2 *Handlers) TealCompile(ctx echo.Context) error {
source := buf.String()
ops, err := logic.AssembleString(source)
if err != nil {
return badRequest(ctx, err, err.Error(), v2.Log)
sb := strings.Builder{}
ops.ReportProblems("", &sb)
return badRequest(ctx, err, sb.String(), v2.Log)
}
pd := logic.HashProgram(ops.Program)
addr := basics.Address(pd)
Expand Down
17 changes: 12 additions & 5 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
"os"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -2109,19 +2108,27 @@ func (ops *OpStream) warnf(format string, a ...interface{}) error {
return ops.warn(fmt.Errorf(format, a...))
}

// ReportProblems issues accumulated warnings and errors to stderr.
func (ops *OpStream) ReportProblems(fname string) {
// ReportProblems issues accumulated warnings and outputs errors to an io.Writer.
func (ops *OpStream) ReportProblems(fname string, writer io.Writer) {
for i, e := range ops.Errors {
if i > 9 {
break
}
fmt.Fprintf(os.Stderr, "%s: %s\n", fname, e)
if fname == "" {
fmt.Fprintf(writer, "%s\n", e)
} else {
fmt.Fprintf(writer, "%s: %s\n", fname, e)
}
}
for i, w := range ops.Warnings {
if i > 9 {
break
}
fmt.Fprintf(os.Stderr, "%s: %s\n", fname, w)
if fname == "" {
fmt.Fprintf(writer, "%s\n", w)
} else {
fmt.Fprintf(writer, "%s: %s\n", fname, w)
}
}
}

Expand Down