Skip to content

Commit

Permalink
fix bad error-messaging (#2437)
Browse files Browse the repository at this point in the history
* more consistent error_handling

* upgrade spectrum for better error-handling

* small fix

* upgrade spectrum

* release script improvements for macOS
  • Loading branch information
k9ert authored May 17, 2024
1 parent 0229bb7 commit e29bc01
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 57 deletions.
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ psycopg2-binary==2.9.5
cryptoadvance-liquidissuer==0.2.4
specterext-exfund==0.1.7
specterext-faucet==0.1.2
cryptoadvance.spectrum==0.6.5
cryptoadvance.spectrum==0.6.7
specterext-stacktrack==0.3.0

# workarounds
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ cryptoadvance-liquidissuer==0.2.4 \
--hash=sha256:5a2c531801854c5a4a46daf184877e22f731cdb42d2cfb840785bda7371ba6fb \
--hash=sha256:9e468f3e35ecc566b3f74a2263677cf26632548abb194521dba15ad37acd1e9b
# via -r requirements.in
cryptoadvance-spectrum==0.6.5 \
--hash=sha256:200bdfbf6cf3a1e25ff6f34ef861f978e9b08e24702278d4d14a024b8dea69a6
cryptoadvance-spectrum==0.6.7 \
--hash=sha256:b9b2350a04b5b33d383939ae284a8f3ff1fab80e1eb5069b710f767d3e7ead52
# via -r requirements.in
cryptography==39.0.1 \
--hash=sha256:0f8da300b5c8af9f98111ffd512910bc792b4c77392a9523624680f7956a99d4 \
Expand Down
34 changes: 23 additions & 11 deletions src/cryptoadvance/specter/templates/includes/message-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@
<message-box type="error">error happened!!!</message-box>
-->
<template id="messagebox">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='output.css') }}">
<style>
#error-text {
/* Additional styles for the slot to allow breaking long unbroken strings */
word-break: break-all; /* This is the key property for breaking long strings */
/* Other styles you might want to apply to #error-text */
}
</style>
<link
rel="stylesheet"
type="text/css"
href="{{ url_for('static', filename='output.css') }}"
/>

<div class="shadow-md rounded-xl px-4 py-3 mr-4 mb-3 bg-dark-500" id="main">
<slot class="text-white" id="error-text">Error: Something bad happened!</slot>
<slot class="text-white" id="error-text"
>Error: Something bad happened!</slot
>
<a class="ml-4 text-white cursor-pointer" id="cancel-icon">&#x2715;</a>
</div>
</template>
Expand All @@ -21,8 +34,8 @@
var style = document.getElementById("messagebox").content;
var clone = style.cloneNode(true);
this.main = clone.querySelector("#main");
this.text = clone.getElementById('error-text')
this.cancelIcon = clone.getElementById('cancel-icon')
this.text = clone.getElementById("error-text");
this.cancelIcon = clone.getElementById("cancel-icon");
clone.querySelector("a").addEventListener("click", (e) => {
this.close();
});
Expand All @@ -46,21 +59,20 @@
}, 200);
}
setType(type) {
if (type === 'error') {
if (type === "error") {
this.main.classList.remove("bg-dark-700");
this.text.classList.remove("text-white");
this.cancelIcon.classList.remove("text-white")
this.cancelIcon.classList.remove("text-white");
this.main.classList.add("bg-red-100");
this.text.classList.add("text-red-700");
this.cancelIcon.classList.add("text-red-700")
}
else if (type == 'warning') {
this.cancelIcon.classList.add("text-red-700");
} else if (type == "warning") {
this.main.classList.remove("bg-dark-700");
this.text.classList.remove("text-white");
this.cancelIcon.classList.remove("text-white")
this.cancelIcon.classList.remove("text-white");
this.main.classList.add("bg-orange-100");
this.text.classList.add("text-orange-700");
this.cancelIcon.classList.add("text-orange-700")
this.cancelIcon.classList.add("text-orange-700");
}
}
connectedCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,26 +446,12 @@
var formData = new FormData();
formData.append("csrf_token", "{{ csrf_token() }}");
formData.append("tx", tx);
try {
const response = await fetch(
url,
{
method: 'POST',
body: formData
}
);
const jsonResponse = await response.json();
if (jsonResponse.success) {
hidePageOverlay();
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
} else {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
}
} catch(e) {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + e);
const jsonResponse = await send_request(url, 'POST', "{{ csrf_token() }}", formData);
if (jsonResponse.success) {
hidePageOverlay();
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
} else {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
}
}
Expand All @@ -480,25 +466,13 @@
formData.append("explorer", explorer);
formData.append("use_tor", useTor);
try {
const response = await fetch(
url,
{
method: 'POST',
body: formData
}
);
const jsonResponse = await response.json();
const jsonResponse = await send_request(url, 'POST', "{{ csrf_token() }}", formData);
if (jsonResponse.success) {
hidePageOverlay();
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
} else {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
}
} catch(e) {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + e);
if (jsonResponse.success) {
hidePageOverlay();
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
} else {
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/cryptoadvance/specterext/spectrum/bridge_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from cryptoadvance.specter.specter_error import BrokenCoreConnectionException

from cryptoadvance.spectrum.spectrum import Spectrum
from cryptoadvance.spectrum.spectrum_error import RPCError

from flask import has_app_context

Expand Down Expand Up @@ -83,6 +84,11 @@ def multi(self, calls: list, **kwargs):

# Spectrum uses a DB and access to it needs an app-context. In order to keep that implementation
# detail within spectrum, we're establishing a context as needed.
class MockResponse:
def __init__(self, status_code=None, text=None):
self.status_code = status_code
self.text = text

try:
if not has_app_context() and self._app is not None:
with self._app.app_context():
Expand All @@ -102,10 +108,11 @@ def multi(self, calls: list, **kwargs):
return result

except ValueError as ve:
mock_response = object()
mock_response.status_code = 500
mock_response.text = ve
mock_response: MockResponse = MockResponse(500, ve)
raise SpecterRpcError(f"Request error: {ve}", mock_response)
except RPCError as rpce:
mock_response: MockResponse = MockResponse(500, rpce.message)
raise SpecterRpcError(f"Request error: {rpce.message}", mock_response)
except SpectrumRpcError as se:
raise SpecterRpcError(
str(se), status_code=500, error_code=se.code, error_msg=se.message
Expand Down
4 changes: 2 additions & 2 deletions utils/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ function help() {

function main() {
# Sed is used as there can be whitespaces
if ! [ "$(git remote -v | grep upstream | grep '[email protected]:cryptoadvance/specter-desktop.git' | wc -l | sed -e 's/\s*//')" = "2" ]; then
if ! [ "$(git remote -v | grep upstream | grep '[email protected]:cryptoadvance/specter-desktop.git' | wc -l | sed -e 's/[[:space:]]*//')" = "2" ]; then
echo " --> You don't have the correct upstream-remote. You need this to release. Please do this:"
echo "git remote add upstream [email protected]:cryptoadvance/specter-desktop.git "
exit 2
fi

if ! [ "$(git remote -v | grep origin | grep '[email protected]:' | wc -l)" = "2" ]; then
if ! [ "$(git remote -v | grep origin | grep '[email protected]:' | wc -l | sed -e 's/[[:space:]]*//')" = "2" ]; then
echo " --> You don't have a reasonable origin-remote. You need this to release (especially with --dev). Please add one!"
exit 2
fi
Expand Down

0 comments on commit e29bc01

Please sign in to comment.