Audio error handling added - first basics, need to be enhanced
This commit is contained in:
+12
-4
@@ -6,6 +6,7 @@
|
|||||||
"ffmpeg-decoder.rkt"
|
"ffmpeg-decoder.rkt"
|
||||||
"audio-sniffer.rkt"
|
"audio-sniffer.rkt"
|
||||||
"private/utils.rkt"
|
"private/utils.rkt"
|
||||||
|
"audio-errors.rkt"
|
||||||
racket/contract
|
racket/contract
|
||||||
racket/string
|
racket/string
|
||||||
racket/path
|
racket/path
|
||||||
@@ -193,13 +194,20 @@
|
|||||||
(let ((file (if (path? audio-file)
|
(let ((file (if (path? audio-file)
|
||||||
(path->string audio-file)
|
(path->string audio-file)
|
||||||
audio-file)))
|
audio-file)))
|
||||||
(unless (audio-file-valid? audio-file)
|
|
||||||
(error (format "Not a valid audio file '~a'" audio-file)))
|
|
||||||
(unless (file-exists? audio-file)
|
(unless (file-exists? audio-file)
|
||||||
(error (format "File '~a' does not exist" audio-file)))
|
(raise-audio-error 'file-not-found
|
||||||
|
"File not found: '~a'" audio-file))
|
||||||
|
|
||||||
|
(unless (audio-file-valid? audio-file)
|
||||||
|
(raise-audio-error 'invalid-audio-file
|
||||||
|
"Not a valid audio file: '~a'" audio-file))
|
||||||
|
|
||||||
(let ((reader* (find-reader audio-file)))
|
(let ((reader* (find-reader audio-file)))
|
||||||
(when (eq? reader* #f)
|
(when (eq? reader* #f)
|
||||||
(error (format "Cannot find reader for '~a'" audio-file)))
|
(raise-audio-error 'no-audio-reader
|
||||||
|
"Cannot find reader for '~a'" audio-file))
|
||||||
|
|
||||||
(let* ((reader-type (car reader*))
|
(let* ((reader-type (car reader*))
|
||||||
(reader (cadr reader*))
|
(reader (cadr reader*))
|
||||||
(ao-type (audio-reader-ao-type reader))
|
(ao-type (audio-reader-ao-type reader))
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require (for-syntax racket/base)
|
||||||
|
racket/path)
|
||||||
|
|
||||||
|
|
||||||
|
(provide exn:fail:audio
|
||||||
|
exn:fail:audio?
|
||||||
|
exn:fail:audio-code
|
||||||
|
raise-audio-error
|
||||||
|
make-audio-error-code
|
||||||
|
exn-audio-code
|
||||||
|
)
|
||||||
|
|
||||||
|
(struct exn:fail:audio exn:fail
|
||||||
|
(code source line)
|
||||||
|
#:transparent)
|
||||||
|
|
||||||
|
(define exn-audio-code exn:fail:audio-code)
|
||||||
|
|
||||||
|
(define (audio-codes)
|
||||||
|
'(no-decoder no-encoder
|
||||||
|
file-not-found
|
||||||
|
invalid-audio-file
|
||||||
|
no-audio-reader
|
||||||
|
audio-file-corrupt
|
||||||
|
audio-error))
|
||||||
|
|
||||||
|
(define (make-audio-code code)
|
||||||
|
(if (symbol? code)
|
||||||
|
(letrec ((f (λ (l)
|
||||||
|
(if (null? (cdr l))
|
||||||
|
(car l)
|
||||||
|
(if (eq? (car l) code)
|
||||||
|
code
|
||||||
|
(f (cdr l)))))))
|
||||||
|
(f (audio-codes)))
|
||||||
|
(make-audio-code (string->symbol (format "~a" code)))))
|
||||||
|
|
||||||
|
(define (make-audio-error-code c)
|
||||||
|
(make-audio-code c))
|
||||||
|
|
||||||
|
|
||||||
|
(define (raise-audio-error* code source line message . args)
|
||||||
|
(let* ((msg (apply format (cons message args)))
|
||||||
|
(src* (file-name-from-path (build-path source)))
|
||||||
|
(msg* (format "~a at ~a, line ~a" msg src* line)))
|
||||||
|
(raise (exn:fail:audio msg*
|
||||||
|
(current-continuation-marks)
|
||||||
|
(make-audio-code code)
|
||||||
|
source
|
||||||
|
line))))
|
||||||
|
|
||||||
|
(define-syntax (raise-audio-error stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
((_ code message ...)
|
||||||
|
(let ((src (syntax-source stx))
|
||||||
|
(line (syntax-line stx)))
|
||||||
|
#`(raise-audio-error* code '#,src '#,line message ...)))))
|
||||||
|
|
||||||
|
(define (test x)
|
||||||
|
(if (> x 10)
|
||||||
|
(raise-audio-error 'file-notd-found "File not found: ~a" "c:/muziek/a.flac")
|
||||||
|
#t))
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user