Skip to content

Commit

Permalink
ensure eth logs are sent to the client on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Jun 26, 2024
1 parent 85ad599 commit f30e943
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 8 additions & 5 deletions ethfull/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
// dont fail the command line yet, go to the return build step
return loop.Seq(
c.msg().StopLoading().Cmd(),
cmdBuildFailed(errors.New("build response is nil")),
cmdBuildFailed(nil, errors.New("build response is nil")),
)
}

Expand All @@ -1003,7 +1003,7 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
return loop.Seq(
// This is not an error, send a loading false to remove the loading spinner
c.msg().Loading(false, "").Cmd(),
cmdBuildFailed(errors.New(resp.Error)),
cmdBuildFailed(resp.Logs, errors.New(resp.Error)),
)
}

Expand Down Expand Up @@ -1047,9 +1047,12 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
case codegen.ReturnBuild:
if msg.Err != nil {
return loop.Seq(
c.msg().Messagef("Remote build failed with error: %s", msg.Err).Cmd(),
c.msg().Message("This module is a Rust-based module, and you can compile it with \"make all\" in the root directory.").Cmd(),
loop.Quit(nil),
c.msg().Messagef("Remote build failed with error: %q. See full logs in `{project-path}/logs.txt`", msg.Err).Cmd(),
c.msg().Messagef("You will need to unzip the 'substreams-src.zip' file and run `make package` to try and generate the .spkg file.").Cmd(),
c.action(codegen.PackageDownloaded{}).
DownloadFiles().
AddFile("logs.txt", []byte(msg.Logs), `text/x-logs`, "").
Cmd(),
)
}
if c.state.confirmDoCompile {
Expand Down
17 changes: 12 additions & 5 deletions ethfull/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func cmdBuild(p *Project) loop.Cmd {
}
}
}
func cmdBuildFailed(err error) loop.Cmd {
func cmdBuildFailed(logs []string, err error) loop.Cmd {
return func() loop.Msg {
return codegen.ReturnBuild{Err: err}
return codegen.ReturnBuild{Err: err, Logs: strings.Join(logs, "\n")}
}
}

Expand Down Expand Up @@ -147,21 +147,28 @@ func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState)
return
}

var aggregatedLogs []string
for {
resp, err := res.Recv()

if resp != nil && resp.Logs != "" {
aggregatedLogs = append(aggregatedLogs, resp.Logs)
}

if err != nil {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Logs: aggregatedLogs,
Error: err.Error(),
}
return
}

if resp == nil {
break
}

if resp.Error != "" {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Logs: aggregatedLogs,
Error: resp.Error,
}
return
Expand All @@ -170,13 +177,13 @@ func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState)
if len(resp.Artifacts) != 0 {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Error: resp.Error,
Logs: []string{resp.Logs},
Logs: aggregatedLogs,
Artifacts: resp.Artifacts,
}
return
}

// send the request as we go
// send the request as we go -- not used on the client yet
remoteBuildContentChan <- &codegen.RemoteBuildState{
Logs: []string{resp.Logs},
}
Expand Down

0 comments on commit f30e943

Please sign in to comment.