Skip to content

Commit fe0ae11

Browse files
committed
Add error handler for new web app editor console
1 parent 8493d77 commit fe0ae11

11 files changed

Lines changed: 141 additions & 41 deletions

core/errors.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package core
33
import (
44
"bytes"
55
"database/sql"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"net"
@@ -176,10 +177,108 @@ func indentString(input string, indentSpaces int, numbering bool) string {
176177
return strings.Join(lines, "\n")
177178
}
178179

180+
const (
181+
// web-safe hex equivalents for the frontend
182+
WebColorRed = "#FF5555" // for color.FgRed
183+
WebColorYellow = "#FFFF55" // for color.FgYellow
184+
WebColorCyan = "#8BE9FD" // for color.FgCyan
185+
WebColorMagenta = "#FF79C6" // for color.FgMagenta
186+
)
187+
188+
type CtxMsg struct {
189+
Message string `json:"msg"`
190+
Depth int `json:"level"`
191+
FullPath string `json:"fullPath"`
192+
}
193+
194+
type WebErrorPayload struct {
195+
IsLeafError bool `json:"isLeafError"`
196+
Context []CtxMsg `json:"context,omitempty"`
197+
198+
Error string `json:"error"`
199+
ErrorColor string `json:"errorColor"`
200+
201+
Hint string `json:"hint,omitempty"`
202+
HintColor string `json:"hintColor,omitempty"`
203+
204+
StackTrace []string `json:"stackTrace,omitempty"`
205+
}
206+
179207
func (e *LeafError) Format(f fmt.State, c rune) {
180208
switch c {
181209
case 'v':
182210

211+
// Below is the JSON output formatting for the web editor console
212+
if f.Flag('#') {
213+
payload := WebErrorPayload{
214+
IsLeafError: true,
215+
Error: e.ErrorWithCauses(),
216+
ErrorColor: "#FF5555",
217+
}
218+
219+
if e.Context != nil && len(e.Context.Visited) > 0 {
220+
var previousNode NodeBaseInterface
221+
for _, item := range e.Context.Visited {
222+
currentNode := item.Node
223+
224+
// TODO: (Seb) improve this
225+
// In the logs, group nodes appear twice, once when entered, and once
226+
// when the group-outputs node comes back and executes the group node again.
227+
// While this is expected for the execution flow, we don't want to have that
228+
// in the logs, it looks very confusing.
229+
if previousNode != nil &&
230+
strings.HasPrefix(previousNode.GetNodeTypeId(), "core/group-outputs@") &&
231+
strings.HasPrefix(currentNode.GetNodeTypeId(), "core/group@") {
232+
233+
previousNode = currentNode
234+
continue
235+
}
236+
237+
nodeNameOrLabel := currentNode.GetLabel()
238+
if nodeNameOrLabel == "" {
239+
nodeNameOrLabel = currentNode.GetName()
240+
}
241+
242+
var msg string
243+
if item.Execute {
244+
msg = fmt.Sprintf("execute '%s'", nodeNameOrLabel)
245+
} else {
246+
msg = fmt.Sprintf("request input from '%s'", nodeNameOrLabel)
247+
}
248+
249+
payload.Context = append(payload.Context, CtxMsg{
250+
Message: msg,
251+
Depth: strings.Count(currentNode.GetFullPath(), "/") + 1,
252+
FullPath: currentNode.GetFullPath(),
253+
})
254+
255+
previousNode = item.Node
256+
}
257+
}
258+
259+
payload.Hint = getErrorHint(e)
260+
if payload.Hint != "" {
261+
payload.HintColor = "#FFFF55"
262+
}
263+
264+
if f.Flag('+') {
265+
rawStack := e.StackTrace()
266+
payload.StackTrace = strings.Split(rawStack, "\n")
267+
}
268+
269+
jsonBytes, err := json.Marshal(payload)
270+
if err != nil {
271+
// Fallback in case of JSON error
272+
fmt.Fprint(f, e.Error())
273+
return
274+
}
275+
276+
fmt.Fprint(f, string(jsonBytes))
277+
return
278+
}
279+
280+
// This below is the regular terminal output formatting
281+
183282
var (
184283
tmpErrEmoji string
185284
tmpHintEmoji string
@@ -245,6 +344,7 @@ func (e *LeafError) Format(f fmt.State, c rune) {
245344

246345
fmt.Fprint(f, output)
247346
return
347+
248348
case 's':
249349
fmt.Fprint(f, e.Error())
250350
}

sessions/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ func runGraphFromConn(ctx context.Context, graphData string, opts core.RunOpts,
945945
// send final error, even if error lines were already streamed
946946
sendEncryptedJSON(ws, map[string]string{
947947
"type": MsgTypeJobError,
948-
"error": fmt.Sprintf("Graph execution failed: %v", runErr),
948+
"error": fmt.Sprintf("%#v", runErr),
949949
}, sharedKey)
950950
return // Exit, the deferred lock release will still run
951951
}

tests_e2e/references/reference_app.sh_l12

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ hint:
2323

2424
stack trace:
2525
github.com/actionforge/actrun-cli/core.RunGraphFromFile
26-
graph.go:1028
26+
graph.go:1031
2727
github.com/actionforge/actrun-cli/cmd.cmdRootRun
2828
cmd_root.go:175
2929
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_dir-walk.sh_l56

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ github.com/actionforge/actrun-cli/nodes.(*WalkNode).ExecuteImpl
3636
github.com/actionforge/actrun-cli/core.(*Executions).Execute
3737
executions.go:56
3838
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteImpl
39-
start@v1.go:49
39+
start@v1.go:50
4040
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteEntry
41-
start@v1.go:44
41+
start@v1.go:45
4242
github.com/actionforge/actrun-cli/core.RunGraph
4343
graph.go:426
4444
github.com/actionforge/actrun-cli/core.RunGraphFromString
45-
graph.go:1013
45+
graph.go:1016
4646
github.com/actionforge/actrun-cli/core.RunGraphFromFile
47-
graph.go:1031
47+
graph.go:1034
4848
github.com/actionforge/actrun-cli/cmd.cmdRootRun
4949
cmd_root.go:175
5050
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_error_no_output.sh_l8

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ github.com/actionforge/actrun-cli/core.(*Outputs).OutputValueById
3737
github.com/actionforge/actrun-cli/core.(*Inputs).InputValueById
3838
inputs.go:364
3939
github.com/actionforge/actrun-cli/core.inputValueById[...]
40-
inputs.go:472
40+
inputs.go:475
4141
github.com/actionforge/actrun-cli/core.InputValueFromSubInputs[...]
42-
inputs.go:467
42+
inputs.go:470
4343
github.com/actionforge/actrun-cli/core.InputArrayValueById[...]
44-
inputs.go:549
44+
inputs.go:552
4545
github.com/actionforge/actrun-cli/nodes.(*PrintNode).ExecuteImpl
4646
print@v1.go:27
4747
github.com/actionforge/actrun-cli/core.(*Executions).Execute
4848
executions.go:56
4949
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteImpl
50-
start@v1.go:49
50+
start@v1.go:50
5151
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteEntry
52-
start@v1.go:44
52+
start@v1.go:45
5353
github.com/actionforge/actrun-cli/core.RunGraph
5454
graph.go:426
5555
github.com/actionforge/actrun-cli/core.RunGraphFromString
56-
graph.go:1013
56+
graph.go:1016
5757
github.com/actionforge/actrun-cli/core.RunGraphFromFile
58-
graph.go:1031
58+
graph.go:1034
5959
github.com/actionforge/actrun-cli/cmd.cmdRootRun
6060
cmd_root.go:175
6161
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_group-error.sh_l8

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ github.com/actionforge/actrun-cli/nodes.(*GroupNode).ExecuteImpl
246246
github.com/actionforge/actrun-cli/core.(*Executions).Execute
247247
executions.go:56
248248
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteImpl
249-
start@v1.go:49
249+
start@v1.go:50
250250
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteEntry
251-
start@v1.go:44
251+
start@v1.go:45
252252
github.com/actionforge/actrun-cli/core.RunGraph
253253
graph.go:426
254254
github.com/actionforge/actrun-cli/core.RunGraphFromString
255-
graph.go:1013
255+
graph.go:1016
256256

tests_e2e/references/reference_group-port-collision.sh_l13

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ github.com/actionforge/actrun-cli/core.LoadGraph
3333
github.com/actionforge/actrun-cli/core.RunGraph
3434
graph.go:275
3535
github.com/actionforge/actrun-cli/core.RunGraphFromString
36-
graph.go:1013
36+
graph.go:1016
3737
github.com/actionforge/actrun-cli/core.RunGraphFromFile
38-
graph.go:1031
38+
graph.go:1034
3939
github.com/actionforge/actrun-cli/cmd.cmdRootRun
4040
cmd_root.go:175
4141
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_index.sh_l20

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ github.com/actionforge/actrun-cli/nodes.(*ArrayGet).OutputValueById
6666
github.com/actionforge/actrun-cli/core.(*Inputs).InputValueById
6767
inputs.go:364
6868
github.com/actionforge/actrun-cli/core.inputValueById[...]
69-
inputs.go:472
69+
inputs.go:475
7070
github.com/actionforge/actrun-cli/core.InputValueFromSubInputs[...]
71-
inputs.go:467
71+
inputs.go:470
7272
github.com/actionforge/actrun-cli/core.InputArrayValueById[...]
73-
inputs.go:549
73+
inputs.go:552
7474
github.com/actionforge/actrun-cli/nodes.(*PrintNode).ExecuteImpl
7575
print@v1.go:27
7676
github.com/actionforge/actrun-cli/core.(*Executions).Execute
@@ -80,15 +80,15 @@ github.com/actionforge/actrun-cli/nodes.(*LoopNode).ExecuteImpl
8080
github.com/actionforge/actrun-cli/core.(*Executions).Execute
8181
executions.go:56
8282
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteImpl
83-
start@v1.go:49
83+
start@v1.go:50
8484
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteEntry
85-
start@v1.go:44
85+
start@v1.go:45
8686
github.com/actionforge/actrun-cli/core.RunGraph
8787
graph.go:426
8888
github.com/actionforge/actrun-cli/core.RunGraphFromString
89-
graph.go:1013
89+
graph.go:1016
9090
github.com/actionforge/actrun-cli/core.RunGraphFromFile
91-
graph.go:1031
91+
graph.go:1034
9292
github.com/actionforge/actrun-cli/cmd.cmdRootRun
9393
cmd_root.go:175
9494
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_run-python-embedded.sh_l13

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ github.com/actionforge/actrun-cli/core.LoadGraph
3737
github.com/actionforge/actrun-cli/core.RunGraph
3838
graph.go:275
3939
github.com/actionforge/actrun-cli/core.RunGraphFromString
40-
graph.go:1013
40+
graph.go:1016
4141
github.com/actionforge/actrun-cli/core.RunGraphFromFile
42-
graph.go:1031
42+
graph.go:1034
4343
github.com/actionforge/actrun-cli/cmd.cmdRootRun
4444
cmd_root.go:175
4545
github.com/spf13/cobra.(*Command).execute

tests_e2e/references/reference_select-data.sh_l9

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ github.com/actionforge/actrun-cli/nodes.(*SelectDataNode).OutputValueById
7373
github.com/actionforge/actrun-cli/core.(*Inputs).InputValueById
7474
inputs.go:364
7575
github.com/actionforge/actrun-cli/core.inputValueById[...]
76-
inputs.go:472
76+
inputs.go:475
7777
github.com/actionforge/actrun-cli/core.InputValueFromSubInputs[...]
78-
inputs.go:467
78+
inputs.go:470
7979
github.com/actionforge/actrun-cli/core.InputArrayValueById[...]
80-
inputs.go:549
80+
inputs.go:552
8181
github.com/actionforge/actrun-cli/nodes.(*PrintNode).ExecuteImpl
8282
print@v1.go:27
8383
github.com/actionforge/actrun-cli/core.(*Executions).Execute
@@ -87,15 +87,15 @@ github.com/actionforge/actrun-cli/nodes.(*LoopNode).ExecuteImpl
8787
github.com/actionforge/actrun-cli/core.(*Executions).Execute
8888
executions.go:56
8989
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteImpl
90-
start@v1.go:49
90+
start@v1.go:50
9191
github.com/actionforge/actrun-cli/nodes.(*StartNode).ExecuteEntry
92-
start@v1.go:44
92+
start@v1.go:45
9393
github.com/actionforge/actrun-cli/core.RunGraph
9494
graph.go:426
9595
github.com/actionforge/actrun-cli/core.RunGraphFromString
96-
graph.go:1013
96+
graph.go:1016
9797
github.com/actionforge/actrun-cli/core.RunGraphFromFile
98-
graph.go:1031
98+
graph.go:1034
9999
github.com/actionforge/actrun-cli/cmd.cmdRootRun
100100
cmd_root.go:175
101101
github.com/spf13/cobra.(*Command).execute

0 commit comments

Comments
 (0)