Skip to content

Commit e29bc01

Browse files
author
k9ert
authored
fix bad error-messaging (#2437)
* more consistent error_handling * upgrade spectrum for better error-handling * small fix * upgrade spectrum * release script improvements for macOS
1 parent 0229bb7 commit e29bc01

File tree

6 files changed

+50
-57
lines changed

6 files changed

+50
-57
lines changed

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ psycopg2-binary==2.9.5
3333
cryptoadvance-liquidissuer==0.2.4
3434
specterext-exfund==0.1.7
3535
specterext-faucet==0.1.2
36-
cryptoadvance.spectrum==0.6.5
36+
cryptoadvance.spectrum==0.6.7
3737
specterext-stacktrack==0.3.0
3838

3939
# workarounds

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ cryptoadvance-liquidissuer==0.2.4 \
155155
--hash=sha256:5a2c531801854c5a4a46daf184877e22f731cdb42d2cfb840785bda7371ba6fb \
156156
--hash=sha256:9e468f3e35ecc566b3f74a2263677cf26632548abb194521dba15ad37acd1e9b
157157
# via -r requirements.in
158-
cryptoadvance-spectrum==0.6.5 \
159-
--hash=sha256:200bdfbf6cf3a1e25ff6f34ef861f978e9b08e24702278d4d14a024b8dea69a6
158+
cryptoadvance-spectrum==0.6.7 \
159+
--hash=sha256:b9b2350a04b5b33d383939ae284a8f3ff1fab80e1eb5069b710f767d3e7ead52
160160
# via -r requirements.in
161161
cryptography==39.0.1 \
162162
--hash=sha256:0f8da300b5c8af9f98111ffd512910bc792b4c77392a9523624680f7956a99d4 \

src/cryptoadvance/specter/templates/includes/message-box.html

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,23 @@
44
<message-box type="error">error happened!!!</message-box>
55
-->
66
<template id="messagebox">
7-
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='output.css') }}">
7+
<style>
8+
#error-text {
9+
/* Additional styles for the slot to allow breaking long unbroken strings */
10+
word-break: break-all; /* This is the key property for breaking long strings */
11+
/* Other styles you might want to apply to #error-text */
12+
}
13+
</style>
14+
<link
15+
rel="stylesheet"
16+
type="text/css"
17+
href="{{ url_for('static', filename='output.css') }}"
18+
/>
819

920
<div class="shadow-md rounded-xl px-4 py-3 mr-4 mb-3 bg-dark-500" id="main">
10-
<slot class="text-white" id="error-text">Error: Something bad happened!</slot>
21+
<slot class="text-white" id="error-text"
22+
>Error: Something bad happened!</slot
23+
>
1124
<a class="ml-4 text-white cursor-pointer" id="cancel-icon">&#x2715;</a>
1225
</div>
1326
</template>
@@ -21,8 +34,8 @@
2134
var style = document.getElementById("messagebox").content;
2235
var clone = style.cloneNode(true);
2336
this.main = clone.querySelector("#main");
24-
this.text = clone.getElementById('error-text')
25-
this.cancelIcon = clone.getElementById('cancel-icon')
37+
this.text = clone.getElementById("error-text");
38+
this.cancelIcon = clone.getElementById("cancel-icon");
2639
clone.querySelector("a").addEventListener("click", (e) => {
2740
this.close();
2841
});
@@ -46,21 +59,20 @@
4659
}, 200);
4760
}
4861
setType(type) {
49-
if (type === 'error') {
62+
if (type === "error") {
5063
this.main.classList.remove("bg-dark-700");
5164
this.text.classList.remove("text-white");
52-
this.cancelIcon.classList.remove("text-white")
65+
this.cancelIcon.classList.remove("text-white");
5366
this.main.classList.add("bg-red-100");
5467
this.text.classList.add("text-red-700");
55-
this.cancelIcon.classList.add("text-red-700")
56-
}
57-
else if (type == 'warning') {
68+
this.cancelIcon.classList.add("text-red-700");
69+
} else if (type == "warning") {
5870
this.main.classList.remove("bg-dark-700");
5971
this.text.classList.remove("text-white");
60-
this.cancelIcon.classList.remove("text-white")
72+
this.cancelIcon.classList.remove("text-white");
6173
this.main.classList.add("bg-orange-100");
6274
this.text.classList.add("text-orange-700");
63-
this.cancelIcon.classList.add("text-orange-700")
75+
this.cancelIcon.classList.add("text-orange-700");
6476
}
6577
}
6678
connectedCallback() {

src/cryptoadvance/specter/templates/wallet/send/sign/wallet_send_sign_psbt.jinja

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -446,26 +446,12 @@
446446
var formData = new FormData();
447447
formData.append("csrf_token", "{{ csrf_token() }}");
448448
formData.append("tx", tx);
449-
450-
try {
451-
const response = await fetch(
452-
url,
453-
{
454-
method: 'POST',
455-
body: formData
456-
}
457-
);
458-
459-
const jsonResponse = await response.json();
460-
461-
if (jsonResponse.success) {
462-
hidePageOverlay();
463-
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
464-
} else {
465-
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
466-
}
467-
} catch(e) {
468-
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + e);
449+
const jsonResponse = await send_request(url, 'POST', "{{ csrf_token() }}", formData);
450+
if (jsonResponse.success) {
451+
hidePageOverlay();
452+
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
453+
} else {
454+
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
469455
}
470456
}
471457
@@ -480,25 +466,13 @@
480466
formData.append("explorer", explorer);
481467
formData.append("use_tor", useTor);
482468
483-
try {
484-
const response = await fetch(
485-
url,
486-
{
487-
method: 'POST',
488-
body: formData
489-
}
490-
);
491-
492-
const jsonResponse = await response.json();
469+
const jsonResponse = await send_request(url, 'POST', "{{ csrf_token() }}", formData);
493470
494-
if (jsonResponse.success) {
495-
hidePageOverlay();
496-
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
497-
} else {
498-
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
499-
}
500-
} catch(e) {
501-
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + e);
471+
if (jsonResponse.success) {
472+
hidePageOverlay();
473+
window.location.replace("{{ url_for('wallets_endpoint.history', wallet_alias=wallet.alias) }}");
474+
} else {
475+
showError(`{{ _('Server failed to broadcast transactions!') }}\n` + jsonResponse.error);
502476
}
503477
}
504478

src/cryptoadvance/specterext/spectrum/bridge_rpc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from cryptoadvance.specter.specter_error import BrokenCoreConnectionException
1717

1818
from cryptoadvance.spectrum.spectrum import Spectrum
19+
from cryptoadvance.spectrum.spectrum_error import RPCError
1920

2021
from flask import has_app_context
2122

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

8485
# Spectrum uses a DB and access to it needs an app-context. In order to keep that implementation
8586
# detail within spectrum, we're establishing a context as needed.
87+
class MockResponse:
88+
def __init__(self, status_code=None, text=None):
89+
self.status_code = status_code
90+
self.text = text
91+
8692
try:
8793
if not has_app_context() and self._app is not None:
8894
with self._app.app_context():
@@ -102,10 +108,11 @@ def multi(self, calls: list, **kwargs):
102108
return result
103109

104110
except ValueError as ve:
105-
mock_response = object()
106-
mock_response.status_code = 500
107-
mock_response.text = ve
111+
mock_response: MockResponse = MockResponse(500, ve)
108112
raise SpecterRpcError(f"Request error: {ve}", mock_response)
113+
except RPCError as rpce:
114+
mock_response: MockResponse = MockResponse(500, rpce.message)
115+
raise SpecterRpcError(f"Request error: {rpce.message}", mock_response)
109116
except SpectrumRpcError as se:
110117
raise SpecterRpcError(
111118
str(se), status_code=500, error_code=se.code, error_msg=se.message

utils/release.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ function help() {
7474

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

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

0 commit comments

Comments
 (0)