Skip to content

Commit

Permalink
Add error message when logs include "ERROR"
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Sep 11, 2023
1 parent 28a6181 commit b38a90a
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 56 deletions.
114 changes: 65 additions & 49 deletions rootfs/usr/share/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@
<img src="/landingpage/static/logo.svg" alt="Home Assistant logo" />
</div>
<div class="content">
<h1>Preparing Home Assistant</h1>
<h2>This may take up to 20 minutes</h2>
<div class="loading">
<div class="progress">
<div class="indeterminate"></div>
<div class="state-normal">
<h1>Preparing Home Assistant</h1>
<h2>This may take up to 20 minutes</h2>
<div class="loading">
<div class="progress">
<div class="indeterminate"></div>
</div>
</div>
<pre id="log"></pre>

<button id="show_logs">Show details</button>
</div>
<div class="state-error">
<h1>Error installing Home Assistant</h1>
<div role="alert" class="alert">
<svg class="alert-icon" preserveAspectRatio="xMidYMid meet" focusable="false" role="img" aria-hidden="true" viewBox="0 0 24 24">
<g>
<path
d="M11,15H13V17H11V15M11,7H13V13H11V7M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20Z">
</path>
</g>
</svg>
<div class="alert-content">
An error occured while installing Home Assistant, check the logs below for more information.
</div>
</div>
</div>
<pre id="log"></pre>
<button id="show_logs">Show details</button>
</div>

<div class="block-container">
Expand Down Expand Up @@ -77,47 +93,47 @@ <h1>Join our community</h1>
</form>
</div>
<div class="link-list">
<a href="https://community.home-assistant.io/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo.svg" />
Home Assistant forums
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://www.home-assistant.io/newsletter/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo.svg" />
Building the Open Home newsletter
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://www.home-assistant.io/join-chat/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo_discord.png" />
Discord chat
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://twitter.com/home_assistant/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo_twitter.png" />
Twitter
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
</div>
<a href="https://community.home-assistant.io/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo.svg" />
Home Assistant forums
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://www.home-assistant.io/newsletter/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo.svg" />
Building the Open Home newsletter
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://www.home-assistant.io/join-chat/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo_discord.png" />
Discord chat
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
<a href="https://twitter.com/home_assistant/" target="_blank" rel="noreferrer noopener" class="link">
<div>
<img loading="lazy" src="/landingpage/static/logo_twitter.png" />
Twitter
</div>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z" />
</svg>
</a>
</div>
</dialog>

<dialog id="dialog-app">
Expand Down
26 changes: 19 additions & 7 deletions rootfs/usr/share/www/static/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,23 @@ function fetchLogs() {
if (res.ok) {
res.text().then(function (text) {
var logElement = document.getElementById("log");
logElement.innerText = logElement.showFull
? text
: ""
.replace(/\s[A-Z]+\s\(\w+\)\s\[[\w.]+\]/gi, "")
.replace(/\d{2}-\d{2}-\d{2}\s/gi, "")
.replace(/\d{2}:\d{2}:\d{2}\s/gi, "");
if (text.includes("ERROR")) {
document.body.classList.add("error");
document.getElementById("show_logs").classList.add("hidden");
logElement.showFull = true;
}
if (!logElement.showFull) {
return;
}
var scrolledDown = logElement.scrollTop + logElement.clientHeight === logElement.scrollHeight;
logElement.innerText = text
.replace(/\s[A-Z]+\s\(\w+\)\s\[[\w.]+\]/gi, "")
.replace(/\d{2}-\d{2}-\d{2}\s/gi, "")
.replace(/\d{2}:\d{2}:\d{2}\s/gi, "");
if (scrolledDown) {
// Scroll content down if it was already scrolled down
logElement.scrollTop = logElement.scrollHeight;
}
});
}
}, scheduleFetchLogs());
Expand All @@ -106,10 +117,11 @@ function toggleLogs(event) {
logElement.showFull = !logElement.showFull;
if (logElement.showFull) {
event.target.innerText = "Hide details";
fetchLogs();
} else {
logElement.innerText = "";
event.target.innerText = "Show details";
}
fetchLogs();
}

var dialogs = document.querySelectorAll('dialog');
Expand Down
49 changes: 49 additions & 0 deletions rootfs/usr/share/www/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ body {
font-size: 12px;
}

.error .state-normal {
display: none;
}

.state-error {
display: none;
}

.error .state-error {
display: block;
}

.alert {
position: relative;
padding: 8px;
margin-bottom: 16px;
display: flex;
align-items: center;
}
.alert::after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 0.12;
pointer-events: none;
content: "";
border-radius: 4px;
background-color: #db4437;
}
.alert-icon {
fill: #db4437;
width: 24px;
flex-shrink: 0;
}
.alert-content {
font-size: 14px;
text-align: left;
margin-left: 8px;
margin-right: 0;
}

.hidden {
display: none;
}

.header {
text-align: center;
margin-top: 32px;
Expand Down Expand Up @@ -288,6 +335,8 @@ pre {
border-radius: 8px;
padding: 16px;
font-family: Roboto Mono, monospace;
max-height: 400px;
overflow: scroll;
}

pre:empty {
Expand Down

0 comments on commit b38a90a

Please sign in to comment.