@@ -135,38 +135,39 @@ export class BlockFactory {
135
135
return this . _getBlockPromise ( identifier ) ;
136
136
}
137
137
138
- async _getBlockPromise ( identifier : FileIdentifier ) : Promise < Block > {
139
-
140
- return this . promises [ identifier ] = this . importer . import ( identifier , this . configuration )
141
- . then ( file => this . _importAndPreprocessBlock ( file ) )
142
- . then ( block => {
143
- debug ( `Finalizing Block object for "${ block . identifier } "` ) ;
144
-
145
- // last check to make sure we don't return a new instance
146
- if ( this . blocks [ block . identifier ] ) {
147
- return this . blocks [ block . identifier ] ;
148
- }
149
-
150
- // Ensure this block name is unique.
151
- block . setName ( this . getUniqueBlockName ( block . name ) ) ;
152
-
153
- // if the block has any errors, surface them here
154
- this . _surfaceBlockErrors ( block ) ;
155
-
156
- return this . blocks [ block . identifier ] = block ;
157
- } )
158
- . catch ( ( error ) => {
159
- if ( this . preprocessQueue . activeJobCount > 0 ) {
160
- debug ( `Block error. Currently there are ${ this . preprocessQueue . activeJobCount } preprocessing jobs. waiting.` ) ;
161
- return this . preprocessQueue . drain ( ) . then ( ( ) => {
162
- debug ( `Drain complete. Raising error.` ) ;
163
- throw error ;
164
- } ) ;
165
- } else {
166
- debug ( `Block error. There are no preprocessing jobs. raising.` ) ;
167
- throw error ;
168
- }
169
- } ) ;
138
+ _getBlockPromise ( identifier : FileIdentifier ) : Promise < Block > {
139
+ return this . promises [ identifier ] = this . _getBlockPromiseAsync ( identifier ) ;
140
+ }
141
+
142
+ async _getBlockPromiseAsync ( identifier : FileIdentifier ) : Promise < Block > {
143
+ try {
144
+ let file = await this . importer . import ( identifier , this . configuration ) ;
145
+ let block = await this . _importAndPreprocessBlock ( file ) ;
146
+ debug ( `Finalizing Block object for "${ block . identifier } "` ) ;
147
+
148
+ // last check to make sure we don't return a new instance
149
+ if ( this . blocks [ block . identifier ] ) {
150
+ return this . blocks [ block . identifier ] ;
151
+ }
152
+
153
+ // Ensure this block name is unique.
154
+ block . setName ( this . getUniqueBlockName ( block . name ) ) ;
155
+
156
+ // if the block has any errors, surface them here unless we're in fault tolerant mode.
157
+ this . _surfaceBlockErrors ( block ) ;
158
+ this . blocks [ block . identifier ] = block ;
159
+ return block ;
160
+ } catch ( error ) {
161
+ if ( this . preprocessQueue . activeJobCount > 0 ) {
162
+ debug ( `Block error. Currently there are ${ this . preprocessQueue . activeJobCount } preprocessing jobs. waiting.` ) ;
163
+ await this . preprocessQueue . drain ( ) ;
164
+ debug ( `Drain complete. Raising error.` ) ;
165
+ throw error ;
166
+ } else {
167
+ debug ( `Block error. There are no preprocessing jobs. raising.` ) ;
168
+ throw error ;
169
+ }
170
+ }
170
171
}
171
172
172
173
/**
0 commit comments