Skip to content

Commit ad61eda

Browse files
committed
Inline errors
1 parent 8ba6560 commit ad61eda

6 files changed

Lines changed: 27 additions & 17 deletions

File tree

assets/css/02_main.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ pre {
127127
text-decoration: line-through !important;
128128
}
129129

130+
.error-inline {
131+
color: var(--red-0);
132+
border: 1px solid var(--red-0);
133+
border-radius: 6px;
134+
padding: 0.6rem 1rem;
135+
margin-bottom: 1rem;
136+
background: var(--deleted);
137+
}
138+
130139
.bold {
131140
font-weight: 600;
132141
}

assets/templates/views/parsed_view.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<div class="view active" id="parse-view">
44
<div class="view-content">
55
<h1>Parse</h1>
6-
{{if .Transactions.Count }}
6+
{{if .Error }}
7+
<div class="error-inline">
8+
<b>Parse error:</b>
9+
<pre>{{ .Error }}</pre>
10+
</div>
11+
{{else if .Transactions.Count }}
712
<p>Use the menu to navigate to the different views.</p>
813
{{ else }}
914
<p>No valid transactions found.</p>

internal/server/html/html.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ func Index(w http.ResponseWriter, data PageData) error {
8989

9090
func Parsed(w http.ResponseWriter, data PageData) error {
9191
parser := vsl.NewTransactionParser(strings.NewReader(data.Logs.Textinput))
92-
ts, err := parser.Parse()
93-
slog.Info("txs", "count", len(ts.Transactions()))
9492

93+
ts, err := parser.Parse()
9594
if err != nil {
9695
slog.Warn("failed to parse logs", "error", err)
97-
98-
return err
96+
data.Error = err
9997
}
10098

99+
slog.Info("txs", "count", len(ts.Transactions()))
100+
101101
data.Transactions.Set = ts
102102
data.Transactions.Count = len(ts.Transactions())
103103

internal/server/routes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func indexHandler(version string) func(http.ResponseWriter, *http.Request) {
4040
const maxRequestBodyBytes = 32 * 1024 * 1024 // 32 MiB
4141

4242
func parseHandler(version string) func(http.ResponseWriter, *http.Request) {
43-
data := html.PageData{Version: version}
44-
4543
return func(w http.ResponseWriter, r *http.Request) {
44+
data := html.PageData{Version: version}
45+
4646
r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodyBytes)
4747

4848
err := r.ParseForm()
@@ -131,9 +131,9 @@ func parseHandler(version string) func(http.ResponseWriter, *http.Request) {
131131
}
132132

133133
func reqBuilderHandler(version string) func(http.ResponseWriter, *http.Request) {
134-
data := html.PageData{Version: version}
135-
136134
return func(w http.ResponseWriter, r *http.Request) {
135+
data := html.PageData{Version: version}
136+
137137
r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodyBytes)
138138

139139
err := r.ParseForm()

render/sequence.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,9 @@ func drawRequest(req *HTTPRequest, truncateLen int) string {
366366

367367
// truncateStr trims the input string to a maximum length, appending "…" if it exceeds the length.
368368
func truncateStr(s string, maxLen int) string {
369-
if utf8.RuneCountInString(s) <= maxLen {
370-
return s
371-
}
372-
373369
runes := []rune(s)
374-
if maxLen > len(runes) {
375-
maxLen = len(runes) // Cap maxLen if it's greater than the length of runes
370+
if len(runes) <= maxLen {
371+
return s
376372
}
377373

378374
return strings.TrimSpace(string(runes[:maxLen])) + "…"
@@ -430,7 +426,7 @@ func wrapAndTruncate(s string, wrapLen, maxLen int) string {
430426
lineLen += wordLen
431427

432428
// Early stop if we already exceed maxLen (slightly before truncation)
433-
if builder.Len() > maxLen {
429+
if utf8.RuneCountInString(builder.String()) > maxLen {
434430
break
435431
}
436432

render/timeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func collectAndSortRecords(ts vsl.TransactionSet, tx *vsl.Transaction, visited m
142142
var events []TimelineEvent
143143

144144
if visited[tx.VXID] {
145-
slog.Info("collectAndSortRecords(): loop detected", "txid", tx.TXID)
145+
slog.Warn("collectAndSortRecords(): loop detected", "txid", tx.TXID)
146146

147147
return events
148148
}

0 commit comments

Comments
 (0)