js: Remove unused catch bindings

Optional catch bindings have been supported for quite a while now,
so we can treat unused error bindings in catch statements like any
other unused variable.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3684>
This commit is contained in:
Florian Müllner 2025-04-01 16:16:07 +02:00 committed by Bruce Leidl
parent a7410d82ac
commit 60aa4319d9
35 changed files with 56 additions and 56 deletions

View File

@ -313,7 +313,7 @@ class Recorder extends Signals.EventEmitter {
// non-pipeline-related failures.
this._updateServiceCrashBlocklist(
[...this._blocklistFromPreviousCrashes, pipelineConfig.id]);
} catch (error) {
} catch {
this._tryNextPipeline();
return;
}

View File

@ -501,7 +501,7 @@ export const LoginDialog = GObject.registerClass({
try {
this._gdmClient.set_enabled_extensions([Gdm.UserVerifierChoiceList.interface_info().name]);
} catch (e) {
} catch {
}
this._settings = new Gio.Settings({schema_id: GdmUtil.LOGIN_SCREEN_SCHEMA});

View File

@ -32,7 +32,7 @@ export function loadInterfaceXML(iface) {
try {
let [ok_, bytes] = f.load_contents(null);
return new TextDecoder().decode(bytes);
} catch (e) {
} catch {
log(`Failed to load D-Bus interface ${iface}`);
}

View File

@ -29,7 +29,7 @@ export function* collectFromDatadirs(subdir, includeUserDir) {
try {
fileEnum = dir.enumerate_children('standard::name,standard::type',
Gio.FileQueryInfoFlags.NONE, null);
} catch (e) {
} catch {
fileEnum = null;
}
if (fileEnum != null) {

View File

@ -87,7 +87,7 @@ class IBusManager extends Signals.EventEmitter {
this._ibusIsSystemdService =
await Shell.util_systemd_unit_exists(
IBUS_SYSTEMD_SERVICE, null);
} catch (e) {
} catch {
this._ibusIsSystemdService = false;
}
@ -216,7 +216,7 @@ class IBusManager extends Signals.EventEmitter {
// confusing users. We thus don't use it in that case.
_checkIBusVersion(1, 5, 10);
this._panelService.connect('set-content-type', this._setContentType.bind(this));
} catch (e) {
} catch {
}
this._updateReadiness();
@ -225,7 +225,7 @@ class IBusManager extends Signals.EventEmitter {
const engine =
await this._ibus.get_global_engine_async(-1, this._cancellable);
this._engineChanged(this._ibus, engine.get_name());
} catch (e) {
} catch {
}
}

View File

@ -126,7 +126,7 @@ export const InputMethod = GObject.registerClass({
_onDeleteSurroundingText(_context, offset, nchars) {
try {
this.delete_surrounding(offset, nchars);
} catch (e) {
} catch {
// We may get out of bounds for negative offset on older mutter
this.delete_surrounding(0, nchars + offset);
}
@ -357,7 +357,7 @@ export const InputMethod = GObject.registerClass({
await this._context.process_key_event_async(
keyval, 0, IBus.ModifierType.RELEASE_MASK, -1, null);
return true;
} catch (e) {
} catch {
return false;
}
}

View File

@ -199,7 +199,7 @@ export async function getPropertyNamesFromExpression(expr, commandHeader = '') {
const lines = expr.split('\n');
lines.push(`return ${lines.pop()}`);
obj = await AsyncFunction(commandHeader + lines.join(';'))();
} catch (e) {
} catch {
return [];
}
} else {

View File

@ -48,7 +48,7 @@ export function canLock() {
let version = result.deepUnpack()[0].deepUnpack();
return haveSystemd() && versionCompare('3.5.91', version);
} catch (e) {
} catch {
return false;
}
}
@ -172,7 +172,7 @@ class LoginManagerSystemd extends Signals.EventEmitter {
const [result] = await this._proxy.CanSuspendAsync();
needsAuth = result === 'challenge';
canSuspend = needsAuth || result === 'yes';
} catch (error) {
} catch {
canSuspend = false;
needsAuth = false;
}
@ -186,7 +186,7 @@ class LoginManagerSystemd extends Signals.EventEmitter {
const [result] = await this._proxy.CanRebootToBootLoaderMenuAsync();
needsAuth = result === 'challenge';
canRebootToBootLoaderMenu = needsAuth || result === 'yes';
} catch (error) {
} catch {
canRebootToBootLoaderMenu = false;
needsAuth = false;
}
@ -202,7 +202,7 @@ class LoginManagerSystemd extends Signals.EventEmitter {
try {
const [sessions] = await this._proxy.ListSessionsAsync();
return sessions;
} catch (e) {
} catch {
return [];
}
}

View File

@ -171,7 +171,7 @@ class ModemGsm extends ModemBase {
]);
this._setOperatorName(_findProviderForMccMnc(name, code));
this._setSignalQuality(quality);
} catch (err) {
} catch {
// it will return an error if the device is not connected
this._setSignalQuality(0);
}
@ -199,7 +199,7 @@ class ModemCdma extends ModemBase {
try {
const [quality] = await this._proxy.GetSignalQualityAsync();
this._setSignalQuality(quality);
} catch (err) {
} catch {
// it will return an error if the device is not connected
this._setSignalQuality(0);
}
@ -210,7 +210,7 @@ class ModemCdma extends ModemBase {
const [bandClass_, band_, sid] =
await this._proxy.GetServingSystemAsync();
this._setOperatorName(_findProviderForSid(sid));
} catch (err) {
} catch {
// it will return an error if the device is not connected
this._setOperatorName(null);
}

View File

@ -340,7 +340,7 @@ const SystemActions = GObject.registerClass({
try {
const [canShutdown] = await this._session.CanShutdownAsync();
this._canHavePowerOff = canShutdown;
} catch (e) {
} catch {
this._canHavePowerOff = false;
}
this._updatePowerOff();

View File

@ -193,7 +193,7 @@ export function fixMarkup(text, allowMarkup) {
try {
Pango.parse_markup(_text, -1, '');
return _text;
} catch (e) {}
} catch {}
}
// !allowMarkup, or invalid markup

View File

@ -1512,7 +1512,7 @@ class AppDisplay extends BaseAppView {
this._appInfoList = Shell.AppSystem.get_default().get_installed().filter(appInfo => {
try {
appInfo.get_id(); // catch invalid file encodings
} catch (e) {
} catch {
return false;
}
return !this._appFavorites.isFavorite(appInfo.get_id()) &&
@ -1737,7 +1737,7 @@ class AppDisplay extends BaseAppView {
schema_id: 'org.gnome.desktop.app-folders.folder',
path: newFolderPath,
});
} catch (e) {
} catch {
log('Error creating new folder');
return false;
}

View File

@ -190,7 +190,7 @@ export class AudioDeviceSelectionDBus {
let dialog;
try {
dialog = new AudioDeviceSelectionDialog(devices);
} catch (e) {
} catch {
invocation.return_value(null);
return;
}

View File

@ -503,7 +503,7 @@ const Background = GObject.registerClass({
Gio.FileQueryInfoFlags.NONE,
0,
this._cancellable);
} catch (e) {
} catch {
this._setLoaded();
return;
}

View File

@ -54,7 +54,7 @@ class AutomountManager {
const [inhibited] =
await this._session.IsInhibitedAsync(GNOME_SESSION_AUTOMOUNT_INHIBIT);
this._inhibited = inhibited;
} catch (e) {}
} catch {}
}
_startupMountAll() {

View File

@ -494,7 +494,7 @@ class VPNRequestHandler extends Signals.EventEmitter {
} else {
try {
this._stdin.write('QUIT\n\n', null);
} catch (e) { /* ignore broken pipe errors */ }
} catch { /* ignore broken pipe errors */ }
}
this.destroy();
@ -544,7 +544,7 @@ class VPNRequestHandler extends Signals.EventEmitter {
if (line === '' && this._previousLine === '') {
try {
this._stdin.write('QUIT\n\n', null);
} catch (e) { /* ignore broken pipe errors */ }
} catch { /* ignore broken pipe errors */ }
} else {
this._agent.add_vpn_secret(this._requestId, this._previousLine, line);
this._previousLine = undefined;

View File

@ -425,7 +425,7 @@ class AuthenticationAgent extends Shell.PolkitAuthenticationAgent {
enable() {
try {
this.register();
} catch (e) {
} catch {
log('Failed to register AuthenticationAgent');
}
}
@ -433,7 +433,7 @@ class AuthenticationAgent extends Shell.PolkitAuthenticationAgent {
disable() {
try {
this.unregister();
} catch (e) {
} catch {
log('Failed to unregister AuthenticationAgent');
}
}

View File

@ -174,7 +174,7 @@ function findAppFromInhibitor(inhibitor) {
let desktopFile;
try {
[desktopFile] = inhibitor.GetAppIdSync();
} catch (e) {
} catch {
// XXX -- sometimes JIT inhibitors generated by gnome-session
// get removed too soon. Don't fail in this case.
log(`gnome-session gave us a dead inhibitor: ${inhibitor.get_object_path()}`);

View File

@ -348,7 +348,7 @@ Object.prototype.toString = function () {
return base.replace(/\]$/, ` delegate for ${this.actor.toString().substring(1)}`);
else
return base;
} catch (e) {
} catch {
return base;
}
};

View File

@ -88,7 +88,7 @@ export function uninstallExtension(uuid) {
const updatesDir = Gio.File.new_for_path(GLib.build_filenamev(
[global.userdatadir, 'extension-updates', extension.uuid]));
FileUtils.recursivelyDeleteDir(updatesDir, true);
} catch (e) {
} catch {
// not an error
}

View File

@ -667,7 +667,7 @@ export class ExtensionManager extends Signals.EventEmitter {
try {
FileUtils.recursivelyDeleteDir(extensionDir, false);
FileUtils.recursivelyMoveDir(dir, extensionDir);
} catch (e) {
} catch {
log(`Failed to install extension updates for ${uuid}`);
} finally {
FileUtils.recursivelyDeleteDir(dir, true);

View File

@ -228,7 +228,7 @@ class IbusCandidatePopup extends BoxPointer.BoxPointer {
rect.width,
rect.height);
});
} catch (e) {
} catch {
// Only recent IBus versions have support for this signal
// which is used for wayland clients. In order to work
// with older IBus versions we can silently ignore the

View File

@ -1439,7 +1439,7 @@ export const Keyboard = GObject.registerClass({
try {
keyboardModel = new KeyboardModel(group);
break;
} catch (e) {
} catch {
// Ignore this error and fall back to next model
}
}

View File

@ -467,7 +467,7 @@ class ObjInspector extends St.ScrollView {
try {
let prop = obj[propName];
link = new ObjLink(this._lookingGlass, prop);
} catch (e) {
} catch {
link = new St.Label({text: '<error>'});
}
let box = new St.BoxLayout();
@ -1589,7 +1589,7 @@ class LookingGlass extends St.BoxLayout {
getResult(idx) {
try {
return this._resultsArea.get_child_at_index(idx - this._offset).o;
} catch (e) {
} catch {
throw new Error(`Unknown result at index ${idx}`);
}
}

View File

@ -156,7 +156,7 @@ export async function start() {
// toString() can throw
if (msg)
args.unshift(`${msg}:`);
} catch (e) {}
} catch {}
console.error(...args);
};

View File

@ -77,7 +77,7 @@ export function loadRemoteSearchProviders(searchSettings) {
try {
keyfile.load_from_file(path, 0);
} catch (e) {
} catch {
return;
}
@ -99,7 +99,7 @@ export function loadRemoteSearchProviders(searchSettings) {
appInfo = Gio.DesktopAppInfo.new(desktopId);
if (!appInfo.should_show())
return;
} catch (e) {
} catch {
log(`Ignoring search provider ${path}: missing DesktopId`);
return;
}
@ -107,14 +107,14 @@ export function loadRemoteSearchProviders(searchSettings) {
let autoStart = true;
try {
autoStart = keyfile.get_boolean(group, 'AutoStart');
} catch (e) {
} catch {
// ignore error
}
let version = '1';
try {
version = keyfile.get_string(group, 'Version');
} catch (e) {
} catch {
// ignore error
}
@ -126,7 +126,7 @@ export function loadRemoteSearchProviders(searchSettings) {
remoteProvider.defaultEnabled = true;
try {
remoteProvider.defaultEnabled = !keyfile.get_boolean(group, 'DefaultDisabled');
} catch (e) {
} catch {
// ignore error
}

View File

@ -2621,7 +2621,7 @@ export class ScreenshotService {
screenshot.screenshot_area(x, y, width, height, stream),
]);
this._onScreenshotComplete(stream, file, invocation);
} catch (e) {
} catch {
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
} finally {
this._removeShooterForSender(invocation.get_sender());
@ -2644,7 +2644,7 @@ export class ScreenshotService {
screenshot.screenshot_window(includeFrame, includeCursor, stream),
]);
this._onScreenshotComplete(stream, file, invocation);
} catch (e) {
} catch {
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
} finally {
this._removeShooterForSender(invocation.get_sender());
@ -2667,7 +2667,7 @@ export class ScreenshotService {
screenshot.screenshot(includeCursor, stream),
]);
this._onScreenshotComplete(stream, file, invocation);
} catch (e) {
} catch {
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
} finally {
this._removeShooterForSender(invocation.get_sender());
@ -2696,7 +2696,7 @@ export class ScreenshotService {
try {
Main.screenshotUI.open(UIMode.SCREENSHOT_ONLY);
} catch (e) {
} catch {
Main.screenshotUI.disconnectObject(invocation);
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
}
@ -2717,7 +2717,7 @@ export class ScreenshotService {
areaRectangle.x, areaRectangle.y,
areaRectangle.width, areaRectangle.height);
invocation.return_value(GLib.Variant.new('(iiii)', retRectangle));
} catch (e) {
} catch {
invocation.return_error_literal(
Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
'Operation was cancelled');
@ -2763,7 +2763,7 @@ export class ScreenshotService {
]),
}]);
invocation.return_value(retval);
} catch (e) {
} catch {
invocation.return_error_literal(
Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED,
'Operation was cancelled');

View File

@ -274,7 +274,7 @@ const SearchResultsBase = GObject.registerClass({
this._setMoreCount(this.provider.canLaunchSearch ? moreCount : 0);
this.show();
callback();
} catch (e) {
} catch {
this._clearResultDisplay();
callback();
}

View File

@ -112,7 +112,7 @@ function _loadMode(file, info) {
[success_, fileContent] = file.load_contents(null);
const decoder = new TextDecoder();
newMode = JSON.parse(decoder.decode(fileContent));
} catch (e) {
} catch {
return;
}

View File

@ -123,7 +123,7 @@ const BackgroundAppMenuItem = GObject.registerClass({
try {
await this.app.activate_action('quit', null, 0, -1, null);
} catch (_error) {
} catch {
try {
const appId = this.app.get_id().replace(/\.desktop$/, '');
Util.trySpawn(['flatpak', 'kill', appId]);

View File

@ -226,7 +226,7 @@ class InputSourceSystemSettings extends InputSourceSettings {
new GLib.Variant('(s)', [this._BUS_IFACE]),
null, Gio.DBusCallFlags.NONE, -1, null);
[props] = result.deepUnpack();
} catch (e) {
} catch {
log(`Could not get properties from ${this._BUS_NAME}`);
return;
}

View File

@ -2126,7 +2126,7 @@ class Indicator extends SystemIndicator {
const state = await this._client.check_connectivity_async(null);
if (state >= NM.ConnectivityState.FULL)
this._portalHandler.removeConnection(path);
} catch (e) { }
} catch {}
});
this._client.connectObject(

View File

@ -499,7 +499,7 @@ export const UnlockDialog = GObject.registerClass({
this._gdmClient.set_enabled_extensions([
Gdm.UserVerifierChoiceList.interface_info().name,
]);
} catch (e) {
} catch {
}
this._adjustment = new St.Adjustment({

View File

@ -18,7 +18,7 @@ function loadInterfaceXML(iface) {
try {
let [ok_, bytes] = f.load_contents(null);
return new TextDecoder().decode(bytes);
} catch (e) {
} catch {
console.error(`Failed to load D-Bus interface ${iface}`);
}

View File

@ -19,7 +19,7 @@ describe('fixMarkup()', () => {
function isMarkupValid(markup) {
try {
Pango.parse_markup(markup, -1, '');
} catch (e) {
} catch {
return false;
}
return true;