Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/core/security/ssl_certificate_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ Future<bool> _isProcessAlive(int owner) async {
return result.exitCode != 0 || '${result.stdout}'.contains('$owner');
}
return (await Process.run('kill', ['-0', '$owner'])).exitCode == 0;
} catch (_) {
} catch (e) {
// Cannot tell: leave the directory alone.
logIgnored('ssl_certificate_support', e);
return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/core/storage/folders_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:querya_desktop/core/storage/app_data_root.dart';

import 'package:querya_desktop/core/util/querya_log.dart';

import 'local_db.dart';

const _legacyFileName = 'folders.json';
Expand Down Expand Up @@ -31,6 +33,7 @@ class FoldersStorage {
// Not marked loaded: the next call reads again instead of caching an
// empty list for the rest of the session.
debugPrint('FoldersStorage.load: $e');
QueryaLog.instance.error('FoldersStorage', 'load failed', error: e);
_folders = [];
}
return folders;
Expand Down Expand Up @@ -62,6 +65,7 @@ class FoldersStorage {
await file.delete();
} catch (e) {
debugPrint('FoldersStorage._migrateFromLegacyIfNeeded: $e');
QueryaLog.instance.error('FoldersStorage', 'legacy folders.json migration failed', error: e);
}
}

Expand Down
12 changes: 11 additions & 1 deletion lib/core/util/querya_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@ class QueryaLog {
Future<void> _append(String line) async {
final dir = _directory!;
final bytes = utf8.encode(line);
if (_size > 0 && _size + bytes.length > maxBytes) await _rotate(dir);
if (_size > 0 && _size + bytes.length > maxBytes) {
try {
await _rotate(dir);
} catch (e) {
// A file that cannot be renamed (open in a viewer, wrong permissions)
// must not stop the log: keep writing to the current file and try
// again after another maxBytes.
debugPrint('QueryaLog: could not rotate: $e');
_size = 0;
}
}
await _file(dir, 0).writeAsBytes(bytes, mode: FileMode.append);
_size += bytes.length;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/features/workspace/generic_sql_workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ class GenericSqlWorkspaceState extends material.State<GenericSqlWorkspace> {
}
}

// The tab may have been closed while the settings read or the dialog was
// pending.
if (!mounted) return;

// Only now: cancelling the destructive dialog above must keep the edits.
if (session.stagingBuffer != null && session.stagingBuffer!.isDirty) {
session.stagingBuffer?.dispose();
Expand Down
15 changes: 15 additions & 0 deletions test/core/util/querya_log_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ void main() {
expect(await read(QueryaLog.fileName), contains('kept'));
});

test('a rotation that fails does not stop the log', () async {
final log = QueryaLog(maxBytes: 100, maxFiles: 2);
await log.init(root);
// A directory where the rotated file must go makes the rename fail.
await Directory(p.join(root.path, 'querya.1.log')).create();
await File(p.join(root.path, 'querya.1.log', 'x')).writeAsString('x');
for (var i = 0; i < 10; i++) {
log.info('t', 'line number $i ${'x' * 20}');
}
log.info('t', 'the last line');
await log.flush();

expect(await read(QueryaLog.fileName), contains('the last line'));
});

test('logIgnored writes to the shared log', () async {
await QueryaLog.instance.init(root);
logIgnored('Somewhere.close', StateError('already closed'));
Expand Down
Loading