mirror of
https://github.com/zoriya/ags.git
synced 2026-08-16 02:45:03 +00:00
better error logging
This commit is contained in:
+7
-7
@@ -146,7 +146,7 @@ export default class App extends Gtk.Application {
|
||||
getWindow(name: string) {
|
||||
const w = this._windows.get(name);
|
||||
if (!w)
|
||||
console.error(`There is no window named ${name}`);
|
||||
console.error(Error(`There is no window named ${name}`));
|
||||
|
||||
return w;
|
||||
}
|
||||
@@ -156,7 +156,7 @@ export default class App extends Gtk.Application {
|
||||
|
||||
const win = this._windows.get(name);
|
||||
if (!win) {
|
||||
console.error('There is no window named ' + name);
|
||||
console.error(Error('There is no window named ' + name));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ export default class App extends Gtk.Application {
|
||||
|
||||
addWindow(w: Gtk.Window) {
|
||||
if (!(w instanceof Gtk.Window)) {
|
||||
console.error(`${w} is not an instanceof Gtk.Window, ` +
|
||||
` but it is of type ${typeof w}`);
|
||||
console.error(Error(`${w} is not an instanceof Gtk.Window, ` +
|
||||
` but it is of type ${typeof w}`));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ export default class App extends Gtk.Application {
|
||||
() => this.emit('window-toggled', w.name, w.visible));
|
||||
|
||||
if (this._windows.has(w.name)) {
|
||||
console.error('There is already a window named' + w.name);
|
||||
console.error(Error('There is already a window named' + w.name));
|
||||
this.quit();
|
||||
return;
|
||||
}
|
||||
@@ -215,7 +215,7 @@ export default class App extends Gtk.Application {
|
||||
|
||||
this.emit('config-parsed');
|
||||
} catch (err) {
|
||||
logError(err as Error);
|
||||
console.error(err as Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ export default class App extends Gtk.Application {
|
||||
}
|
||||
else { print(`${out}`); }
|
||||
})
|
||||
.catch(logError);
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
ToggleWindow(name: string) {
|
||||
|
||||
@@ -112,7 +112,7 @@ class ApplicationsService extends Service {
|
||||
|
||||
ensureDirectory(APPS_CACHE_DIR);
|
||||
const json = JSON.stringify(this._frequents, null, 2);
|
||||
writeFile(json, CACHE_FILE).catch(logError);
|
||||
writeFile(json, CACHE_FILE).catch(console.error);
|
||||
this.notify('frequents');
|
||||
this.emit('changed');
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class BluetoothService extends Service {
|
||||
callback(s);
|
||||
this.changed('connected-devices');
|
||||
} catch (error) {
|
||||
logError(error as Error);
|
||||
console.error(error as Error);
|
||||
callback(false);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -174,7 +174,7 @@ class HyprlandService extends Service {
|
||||
});
|
||||
this.notify('monitors');
|
||||
} catch (error) {
|
||||
logError(error as Error);
|
||||
console.error(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ class HyprlandService extends Service {
|
||||
});
|
||||
this.notify('workspaces');
|
||||
} catch (error) {
|
||||
logError(error as Error);
|
||||
console.error(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class HyprlandService extends Service {
|
||||
});
|
||||
this.notify('clients');
|
||||
} catch (error) {
|
||||
logError(error as Error);
|
||||
console.error(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ class HyprlandService extends Service {
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
logError(error as Error);
|
||||
console.error(error as Error);
|
||||
}
|
||||
|
||||
this.emit('changed');
|
||||
|
||||
@@ -204,8 +204,9 @@ class MprisPlayer extends Service {
|
||||
source.copy_finish(result);
|
||||
this.changed('cover-path');
|
||||
}
|
||||
catch (e) {
|
||||
logError(e as Error, `failed to cache ${this._coverPath}`);
|
||||
catch (err) {
|
||||
console.error(`failed to cache ${this._coverPath}`);
|
||||
console.error(err as Error);
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -245,12 +246,12 @@ class MprisPlayer extends Service {
|
||||
this.emit('position', time);
|
||||
}
|
||||
|
||||
playPause() { this._playerProxy.PlayPauseAsync().catch(logError); }
|
||||
play() { this._playerProxy.PlayAsync().catch(logError); }
|
||||
stop() { this._playerProxy.StopAsync().catch(logError); }
|
||||
playPause() { this._playerProxy.PlayPauseAsync().catch(console.error); }
|
||||
play() { this._playerProxy.PlayAsync().catch(console.error); }
|
||||
stop() { this._playerProxy.StopAsync().catch(console.error); }
|
||||
|
||||
next() { this._playerProxy.NextAsync().catch(logError); }
|
||||
previous() { this._playerProxy.PreviousAsync().catch(logError); }
|
||||
next() { this._playerProxy.NextAsync().catch(console.error); }
|
||||
previous() { this._playerProxy.PreviousAsync().catch(console.error); }
|
||||
|
||||
shuffle() { this._playerProxy.Shuffle = !this._playerProxy.Shuffle; }
|
||||
loop() {
|
||||
|
||||
@@ -238,7 +238,7 @@ class NetworkService extends Service {
|
||||
this._clientReady();
|
||||
}
|
||||
catch (e) {
|
||||
logError(e as Error);
|
||||
console.error(e as Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ class NotificationsService extends Service {
|
||||
private _cache() {
|
||||
ensureDirectory(NOTIFICATIONS_CACHE_PATH);
|
||||
const arr = Array.from(this._notifications.values()).map(n => n.toJson());
|
||||
writeFile(JSON.stringify(arr, null, 2), CACHE_FILE).catch(logError);
|
||||
writeFile(JSON.stringify(arr, null, 2), CACHE_FILE).catch(console.error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -4,7 +4,6 @@ import GLib from 'gi://GLib';
|
||||
import GObject from 'gi://GObject';
|
||||
import { Command } from './widgets/constructor.js';
|
||||
|
||||
|
||||
export const USER = GLib.get_user_name();
|
||||
export const CACHE_DIR = `${GLib.get_user_cache_dir()}/${pkg.name.split('.').pop()}`;
|
||||
|
||||
@@ -63,7 +62,7 @@ export function loadInterfaceXML(iface: string) {
|
||||
const [, bytes] = f.load_contents(null);
|
||||
return new TextDecoder().decode(bytes);
|
||||
} catch (e) {
|
||||
logError(e as Error);
|
||||
console.error(e as Error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -73,8 +72,7 @@ export function bulkConnect(
|
||||
service: GObject.Object,
|
||||
list: [
|
||||
event: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
callback: (...args: any[]) => void
|
||||
callback: (...args: unknown[]) => void
|
||||
][],
|
||||
) {
|
||||
const ids = [];
|
||||
@@ -212,7 +210,7 @@ export function exec(cmd: string) {
|
||||
export function subprocess(
|
||||
cmd: string | string[],
|
||||
callback: (out: string) => void,
|
||||
onError = logError,
|
||||
onError = console.error,
|
||||
bind?: Gtk.Widget,
|
||||
) {
|
||||
try {
|
||||
|
||||
+8
-8
@@ -50,16 +50,16 @@ class AgsVariable extends GObject.Object {
|
||||
|
||||
startPoll() {
|
||||
if (!this._poll)
|
||||
return console.error(`${this} has no poll defined`);
|
||||
return console.error(Error(`${this} has no poll defined`));
|
||||
|
||||
if (this._interval)
|
||||
return console.error(`${this} is already polling`);
|
||||
return console.error(Error(`${this} is already polling`));
|
||||
|
||||
const [time, cmd, transform = out => out] = this._poll;
|
||||
if (Array.isArray(cmd) || typeof cmd === 'string') {
|
||||
this._interval = interval(time, () => execAsync(cmd)
|
||||
.then(out => this.setValue(transform(out)))
|
||||
.catch(logError));
|
||||
.catch(console.error));
|
||||
}
|
||||
if (typeof cmd === 'function')
|
||||
this._interval = interval(time, () => this.setValue(cmd()));
|
||||
@@ -70,16 +70,16 @@ class AgsVariable extends GObject.Object {
|
||||
GLib.source_remove(this._interval);
|
||||
this._interval = 0;
|
||||
} else {
|
||||
console.error(`${this} has no poll running`);
|
||||
console.error(Error(`${this} has no poll running`));
|
||||
}
|
||||
}
|
||||
|
||||
startListen() {
|
||||
if (!this._listen)
|
||||
return console.error(`${this} has no listen defined`);
|
||||
return console.error(Error(`${this} has no listen defined`));
|
||||
|
||||
if (this._subprocess)
|
||||
return console.error(`${this} is already listening`);
|
||||
return console.error(Error(`${this} is already listening`));
|
||||
|
||||
let cmd: string | string[];
|
||||
const transform = typeof this._listen[1] === 'function'
|
||||
@@ -99,7 +99,7 @@ class AgsVariable extends GObject.Object {
|
||||
cmd = this._listen[0];
|
||||
|
||||
else
|
||||
return console.error(`${this._listen} is not a valid type for Variable.listen`);
|
||||
return console.error(Error(`${this._listen} is not a valid type for Variable.listen`));
|
||||
|
||||
this._subprocess = subprocess(cmd, out => this.setValue(transform(out)));
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class AgsVariable extends GObject.Object {
|
||||
this._subprocess.force_exit();
|
||||
this._subprocess = null;
|
||||
} else {
|
||||
console.error(`${this} has no listen running`);
|
||||
console.error(Error(`${this} has no listen running`));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ export const Scrollable = (args: object) => constructor(AgsScrollable, args);
|
||||
export const Slider = (args: object) => constructor(AgsSlider, args);
|
||||
export const Stack = (args: object) => constructor(AgsStack, args);
|
||||
|
||||
// so it is still in global scope through ags.Widget
|
||||
// so they are still accessible when importing only Widget
|
||||
Widget.Widget = Widget;
|
||||
Widget.Box = Box;
|
||||
Widget.Button = Button;
|
||||
|
||||
@@ -97,7 +97,7 @@ function parseCommon(widget: Gtk.Widget, {
|
||||
if (binds) {
|
||||
binds.forEach(([prop, obj, objProp = 'value', transform = out => out]) => {
|
||||
if (!prop || !obj) {
|
||||
logError(new Error('missing arguments to binds'));
|
||||
console.error(Error('missing arguments to binds'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ function parseCommon(widget: Gtk.Widget, {
|
||||
if (connections) {
|
||||
connections.forEach(([s, callback, event]) => {
|
||||
if (!s || !callback) {
|
||||
logError(new Error('missing arguments to connections'));
|
||||
console.error(Error('missing arguments to connections'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ function parseCommon(widget: Gtk.Widget, {
|
||||
connect(s, widget, callback, event);
|
||||
|
||||
else
|
||||
logError(new Error(`${s} is not connectable`));
|
||||
console.error(Error(`${s} is not connectable`));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ export default class AgsIcon extends Gtk.Image {
|
||||
}
|
||||
}
|
||||
else {
|
||||
logError(new Error(`expected Pixbuf or string for icon, but got ${typeof icon}`));
|
||||
console.error(Error(`expected Pixbuf or string for icon, but got ${typeof icon}`));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export default class AgsLabel extends Gtk.Label {
|
||||
if (e instanceof GLib.MarkupError)
|
||||
label = GLib.markup_escape_text(label, -1);
|
||||
else
|
||||
logError(e as Error);
|
||||
console.error(e as Error);
|
||||
}
|
||||
}
|
||||
super.label = label;
|
||||
|
||||
Vendored
+2
-3
@@ -1,7 +1,4 @@
|
||||
declare function print(...args: any[]): void;
|
||||
declare function log(obj: object, others?: object[]): void;
|
||||
declare function log(msg: string, subsitutions?: any[]): void;
|
||||
declare function logError(err: Error, msg?: string): void;
|
||||
|
||||
declare const pkg: {
|
||||
version: string;
|
||||
@@ -17,6 +14,8 @@ declare const imports: {
|
||||
declare module console {
|
||||
export function error(obj: object, others?: object[]): void;
|
||||
export function error(msg: string, subsitutions?: any[]): void;
|
||||
export function log(obj: object, others?: object[]): void;
|
||||
export function log(msg: string, subsitutions?: any[]): void;
|
||||
}
|
||||
|
||||
declare interface String {
|
||||
|
||||
Reference in New Issue
Block a user