Skip to content

Commit

Permalink
Improved error formatting on index page
Browse files Browse the repository at this point in the history
  • Loading branch information
kellpossible committed Apr 14, 2024
1 parent 12e7a80 commit b00a41f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/dist
/data
.env.toml
.env.toml.*
.env

# Spreadsheet Lock Files
Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub async fn handler(
.fold((Vec::new(), Vec::new()), |mut acc, result| async move {
match result {
Ok(ok) => acc.0.push(ok),
Err(error) => acc.1.push(error.to_string()),
Err(error) => acc.1.push(format!("{error:?}")),
}
acc
})
Expand Down
25 changes: 25 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,31 @@ pub async fn middleware(
},
)
});
environment.add_function("limit_line_length", |string: &str, length: usize| {
let mut new_string = String::with_capacity(string.len());
for line in string.lines() {
let mut line = line;
if line.chars().count() <= length {
new_string.push_str(line);
new_string.push('\n');
continue;
}
while line.chars().count() > length {
let split_position = line
.char_indices()
.enumerate()
.find_map(|(i, (p, _c))| if i >= length { Some(p) } else { None })
.expect("Expected to find split position");
let (before, after) = line.split_at(split_position);
new_string.push_str(before);
new_string.push('\n');
line = after;
}
new_string.push_str(line);
new_string.push('\n');
}
new_string
});
let uri = request.uri();
let query_value: Value = uri
.query()
Expand Down
6 changes: 5 additions & 1 deletion src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ <h2 class="text-2xl font-bold py-2">{{ fl("forecast-archive-heading") }}</h2>
<h2 class="text-2xl font-bold text-rose-600">Errors Reading Forecast Files</h2>
{% for error in errors %}
<h3 class="text-xl font-bold text-rose-600">Error {{ loop.index }}</h3>
<pre>{{ ansi_to_html(error) }}</pre>
{% autoescape false %}
<pre class="text-left text-sm max-w-full"
style="overflow-wrap: break-word;
white-space: pre-wrap">{{ ansi_to_html(error) }}</pre>
{% endautoescape %}
{% endfor %}
{% endif %}
</div>
Expand Down

0 comments on commit b00a41f

Please sign in to comment.