Skip to content

Commit

Permalink
Work around missing GLib.Error.stack
Browse files Browse the repository at this point in the history
Work around gjsify/ts-for-gir#196 by declaring
the stack attribute explicitly.
  • Loading branch information
swsnr committed Sep 7, 2024
1 parent 4c3076b commit e7db80a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/lib/fixes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright Sebastian Wiesner <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Alternatively, the contents of this file may be used under the terms
// of the GNU General Public License Version 2 or later, as described below:
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import type GLib from "gi://GLib";

/**
* This module provides workarounds and fixes for various incomplete type
* declarations in Gnome shell types and its dependencies.
*/

/**
* @see https://github.com/gjsify/ts-for-gir/issues/196
*/
export interface GLibErrorWithStack extends GLib.Error {
readonly stack: string;
}
3 changes: 2 additions & 1 deletion src/lib/ui/error-detail-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { pgettext } from "resource:///org/gnome/shell/extensions/extension.js";

import { ModalDialog } from "resource:///org/gnome/shell/ui/modalDialog.js";
import { unfoldCauses } from "../common/error.js";
import { GLibErrorWithStack } from "../fixes.js";

/**
* Shortcut for `GLib.markup_escape_text`.
Expand Down Expand Up @@ -55,7 +56,7 @@ const formatOneError = (error: unknown): string => {
const stack = formatStacktrace(error.stack);
return `<b>${e(error.name)}: ${e(error.message)}</b>\n${stack}`;
} else if (error instanceof GLib.Error) {
const stack = formatStacktrace(error.stack);
const stack = formatStacktrace((error as GLibErrorWithStack).stack);
return `<b>${error.toString()}</b>\n${stack}`;
} else if (typeof error === "string") {
return e(`<b>${error}</b>`);
Expand Down

0 comments on commit e7db80a

Please sign in to comment.