Skip to content

Commit 7717782

Browse files
committed
exceptions.scm: New module with some "safe" procedure wrappers.
When an exception is thrown, show the message to the user via GUI `player:alert`. It's not pretty but it's better than crashing the process.
1 parent 67f7c58 commit 7717782

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Spotiqueue.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
DAFAB407265D1BE90096810C /* NSImageViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAFAB406265D1BE90096810C /* NSImageViewExtensions.swift */; };
4343
EC34C8A32664D92300786C78 /* OptionSetExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC34C8A22664D92300786C78 /* OptionSetExtensions.swift */; };
4444
EC34C8B82665C17C00786C78 /* ComparableExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC34C8B72665C17C00786C78 /* ComparableExtensions.swift */; };
45+
EC67297A277BDE8F003CF0AC /* exceptions.scm in CopyFiles */ = {isa = PBXBuildFile; fileRef = EC672973277BDE17003CF0AC /* exceptions.scm */; };
4546
EC97CFB02679E29000A0361C /* AppMover in Frameworks */ = {isa = PBXBuildFile; productRef = EC97CFAF2679E29000A0361C /* AppMover */; };
4647
EC97CFB5267AFFA400A0361C /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EC97CFB3267AFF7700A0361C /* Sparkle.framework */; };
4748
EC97CFB6267AFFA400A0361C /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EC97CFB3267AFF7700A0361C /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -69,6 +70,7 @@
6970
dstSubfolderSpec = 7;
7071
files = (
7172
DA2E8A1C26ED9578003BF91C /* init.scm in CopyFiles */,
73+
EC67297A277BDE8F003CF0AC /* exceptions.scm in CopyFiles */,
7274
DA2E8A1F26ED9580003BF91C /* key-constants.scm in CopyFiles */,
7375
DA2E8A1E26ED957D003BF91C /* keybindings.scm in CopyFiles */,
7476
DA2E8A1D26ED957A003BF91C /* records.scm in CopyFiles */,
@@ -127,6 +129,7 @@
127129
DAFAB406265D1BE90096810C /* NSImageViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSImageViewExtensions.swift; sourceTree = "<group>"; };
128130
EC34C8A22664D92300786C78 /* OptionSetExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionSetExtensions.swift; sourceTree = "<group>"; };
129131
EC34C8B72665C17C00786C78 /* ComparableExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComparableExtensions.swift; sourceTree = "<group>"; };
132+
EC672973277BDE17003CF0AC /* exceptions.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = exceptions.scm; sourceTree = "<group>"; };
130133
EC97CFB3267AFF7700A0361C /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Spotiqueue/Sparkle.framework; sourceTree = "<group>"; };
131134
EC9B31A62677048000E5C44B /* RBLoginWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RBLoginWindow.swift; sourceTree = "<group>"; };
132135
EC9B31A72677048000E5C44B /* RBLoginWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = RBLoginWindow.xib; sourceTree = "<group>"; };
@@ -160,6 +163,7 @@
160163
DA2F7CF826F5854A00FE1A5F /* spotiqueue */ = {
161164
isa = PBXGroup;
162165
children = (
166+
EC672973277BDE17003CF0AC /* exceptions.scm */,
163167
DAE88E2F26E8AAA300125A3F /* init.scm */,
164168
DA2E89FA26EC8929003BF91C /* key-constants.scm */,
165169
DA2E89F226EC6741003BF91C /* keybindings.scm */,

guile/spotiqueue/exceptions.scm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;;; BEGIN exceptions.scm
2+
;;;
3+
;;; Copyright © 2021 paul at denknerd dot org
4+
;;;
5+
;;; This file contains code for handling exceptions and showing the error message to the Spotiqueue
6+
;;; GUI user.
7+
(define-module (spotiqueue exceptions)
8+
#:use-module (ice-9 exceptions)
9+
#:use-module (ice-9 optargs)
10+
#:use-module (spotiqueue internal))
11+
(module-export-all! (current-module))
12+
13+
(define (spot:with-exn-handler thunk)
14+
(with-exception-handler spot:handler thunk #:unwind? #t))
15+
16+
(define (spot:safe-run-hook hook args)
17+
(spot:with-exn-handler (lambda () (apply run-hook (cons hook args)))))
18+
19+
(define (spot:handler exn)
20+
(let ((message (cond (exception-with-message? exn) (exception-message exn)
21+
(else "(no message)"))))
22+
(format #t "[spotiqueue exception] Raised: ~a~%" message)
23+
(player:alert "Guile Exception" (format #f "~a" message))))
24+
25+
(define (spot:safe-primitive-load file)
26+
(spot:with-exn-handler (lambda ()
27+
(primitive-load file))))
28+
29+
;;; END exceptions.scm

guile/spotiqueue/init.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
(define-module (spotiqueue init)
1515
#:use-module (ice-9 format)
16+
#:use-module (spotiqueue exceptions)
1617
#:use-module (spotiqueue internal)
1718
#:use-module (spotiqueue records)
1819
#:use-module (spotiqueue keybindings)

0 commit comments

Comments
 (0)