@@ -12,17 +12,28 @@ type DemoAudioData = {
12
12
} ;
13
13
14
14
export async function getDemoAudioData ( checksum : string , audioFilePath : string ) : Promise < DemoAudioData | null > {
15
- const extension = path . parse ( audioFilePath ) . ext . slice ( 1 ) . toLowerCase ( ) ;
16
- if ( ! supportedAudioExtensions . includes ( extension ) ) {
17
- return null ;
18
- }
19
- const fileExists = await pathExists ( audioFilePath ) ;
20
- if ( ! fileExists ) {
21
- return null ;
22
- }
15
+ try {
16
+ const extension = path . parse ( audioFilePath ) . ext . slice ( 1 ) . toLowerCase ( ) ;
17
+ if ( ! supportedAudioExtensions . includes ( extension ) ) {
18
+ return null ;
19
+ }
20
+ const fileExists = await pathExists ( audioFilePath ) ;
21
+ if ( ! fileExists ) {
22
+ return null ;
23
+ }
23
24
24
- const offsetSeconds = getDemoAudioOffset ( checksum ) ;
25
- const [ audio , bytes ] = await Promise . all ( [ loadAudio ( audioFilePath ) , readFile ( audioFilePath ) ] ) ;
25
+ const offsetSeconds = getDemoAudioOffset ( checksum ) ;
26
+ const [ audio , bytes ] = await Promise . all ( [ loadAudio ( audioFilePath ) , readFile ( audioFilePath ) ] ) ;
26
27
27
- return { audioFilePath, audio, audioBytes : bytes , offsetSeconds } ;
28
+ return { audioFilePath, audio, audioBytes : bytes , offsetSeconds } ;
29
+ } catch ( error ) {
30
+ logger . error ( 'Error loading demo audio data' , audioFilePath ) ;
31
+ logger . error ( error ) ;
32
+ if ( error instanceof Error ) {
33
+ logger . error ( error . name ) ;
34
+ logger . error ( error . message ) ;
35
+ logger . error ( error . stack ) ;
36
+ }
37
+ throw error ;
38
+ }
28
39
}
0 commit comments