fix: Display errors from isolates in the logs
This commit is contained in:
parent
0a9f8497e2
commit
9012ce6b2c
|
|
@ -213,11 +213,13 @@ class SSSS {
|
|||
content.passphrase.iterations = PBKDF2_DEFAULT_ITERATIONS;
|
||||
content.passphrase.bits = SSSS_KEY_LENGTH * 8;
|
||||
privateKey = await runInBackground(
|
||||
_keyFromPassphrase,
|
||||
_KeyFromPassphraseArgs(
|
||||
passphrase: passphrase,
|
||||
info: content.passphrase,
|
||||
));
|
||||
_keyFromPassphrase,
|
||||
_KeyFromPassphraseArgs(
|
||||
passphrase: passphrase,
|
||||
info: content.passphrase,
|
||||
),
|
||||
timeout: Duration(seconds: 10),
|
||||
);
|
||||
} else {
|
||||
// we need to just generate a new key from scratch
|
||||
privateKey = Uint8List.fromList(SecureRandom(SSSS_KEY_LENGTH).bytes);
|
||||
|
|
@ -648,11 +650,13 @@ class OpenSSSS {
|
|||
'Tried to unlock with passphrase while key does not have a passphrase');
|
||||
}
|
||||
privateKey = await runInBackground(
|
||||
_keyFromPassphrase,
|
||||
_KeyFromPassphraseArgs(
|
||||
passphrase: passphrase,
|
||||
info: keyData.passphrase,
|
||||
));
|
||||
_keyFromPassphrase,
|
||||
_KeyFromPassphraseArgs(
|
||||
passphrase: passphrase,
|
||||
info: keyData.passphrase,
|
||||
),
|
||||
timeout: Duration(seconds: 10),
|
||||
);
|
||||
} else if (recoveryKey != null) {
|
||||
privateKey = SSSS.decodeRecoveryKey(recoveryKey);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,16 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:isolate/isolate.dart';
|
||||
import 'dart:async';
|
||||
|
||||
Future<T> runInBackground<T, U>(
|
||||
FutureOr<T> Function(U arg) function, U arg) async {
|
||||
FutureOr<T> Function(U arg) function,
|
||||
U arg, {
|
||||
Duration timeout,
|
||||
dynamic Function() onTimeout,
|
||||
}) async {
|
||||
IsolateRunner isolate;
|
||||
try {
|
||||
isolate = await IsolateRunner.spawn();
|
||||
|
|
@ -28,9 +33,17 @@ Future<T> runInBackground<T, U>(
|
|||
// web does not support isolates (yet), so we fall back to calling the method directly
|
||||
return await function(arg);
|
||||
}
|
||||
final sub = isolate.errors
|
||||
.listen((error) => Logs().e('Error caught in isolate', error));
|
||||
try {
|
||||
return await isolate.run(function, arg);
|
||||
return await isolate.run(
|
||||
function,
|
||||
arg,
|
||||
timeout: timeout,
|
||||
onTimeout: onTimeout,
|
||||
);
|
||||
} finally {
|
||||
await sub.cancel();
|
||||
await isolate.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue