@@ -207,71 +207,75 @@ export class Builder {
207207 const filesSectionEmptyStatus = fileHelper . filesSectionEmptyStatus ( clonedLuContents )
208208 let isAllLuEmpty = [ ...filesSectionEmptyStatus . values ( ) ] . every ( ( isEmpty ) => isEmpty )
209209
210- if ( ! isAllLuEmpty ) {
211- const luBuildCore = new LuBuildCore ( authoringKey , endpoint , retryCount , retryDuration )
212- const apps = await luBuildCore . getApplicationList ( )
213-
214- let settings : any
215-
216- // here we do a while loop to make full use of luis tps capacity
217- while ( clonedLuContents . length > 0 ) {
218- // get a number(set by luisApiTps) of contents for each loop
219- const subLuContents = clonedLuContents . splice ( 0 , luisAPITPS )
220-
221- // concurrently handle applications
222- await Promise . all ( subLuContents . map ( async content => {
223- if ( ! filesSectionEmptyStatus . get ( content . path ) ) {
224- // init current application object from lu content
225- let currentApp = await this . initApplicationFromLuContent ( content , botName , suffix )
226-
227- // init recognizer asset
228- const dialogFile = path . join ( path . dirname ( content . path ) , `${ content . name } .dialog` )
229- let recognizer = new Recognizer ( content . path , content . name , dialogFile , schema )
230-
231- // find if there is a matched name with current app under current authoring key
232- if ( ! recognizer . getAppId ( ) ) {
233- for ( let app of apps ) {
234- if ( app . name === currentApp . name ) {
235- recognizer . setAppId ( app . id )
236- break
210+ try {
211+ if ( ! isAllLuEmpty ) {
212+ const luBuildCore = new LuBuildCore ( authoringKey , endpoint , retryCount , retryDuration )
213+ const apps = await luBuildCore . getApplicationList ( )
214+
215+ let settings : any
216+
217+ // here we do a while loop to make full use of luis tps capacity
218+ while ( clonedLuContents . length > 0 ) {
219+ // get a number(set by luisApiTps) of contents for each loop
220+ const subLuContents = clonedLuContents . splice ( 0 , luisAPITPS )
221+
222+ // concurrently handle applications
223+ await Promise . all ( subLuContents . map ( async content => {
224+ if ( ! filesSectionEmptyStatus . get ( content . path ) ) {
225+ // init current application object from lu content
226+ let currentApp = await this . initApplicationFromLuContent ( content , botName , suffix )
227+
228+ // init recognizer asset
229+ const dialogFile = path . join ( path . dirname ( content . path ) , `${ content . name } .dialog` )
230+ let recognizer = new Recognizer ( content . path , content . name , dialogFile , schema )
231+
232+ // find if there is a matched name with current app under current authoring key
233+ if ( ! recognizer . getAppId ( ) ) {
234+ for ( let app of apps ) {
235+ if ( app . name === currentApp . name ) {
236+ recognizer . setAppId ( app . id )
237+ break
238+ }
237239 }
238240 }
239- }
240241
241- let needTrainAndPublish = false
242+ let needTrainAndPublish = false
242243
243- // compare models to update the model if a match found
244- // otherwise create a new application
245- if ( recognizer . getAppId ( ) && recognizer . getAppId ( ) !== '' ) {
246- // To see if need update the model
247- needTrainAndPublish = await this . updateApplication ( currentApp , luBuildCore , recognizer , timeBucketOfRequests , keptVersionCount )
248- } else {
249- // create a new application
250- needTrainAndPublish = await this . createApplication ( currentApp , luBuildCore , recognizer , timeBucketOfRequests )
251- }
244+ // compare models to update the model if a match found
245+ // otherwise create a new application
246+ if ( recognizer . getAppId ( ) && recognizer . getAppId ( ) !== '' ) {
247+ // To see if need update the model
248+ needTrainAndPublish = await this . updateApplication ( currentApp , luBuildCore , recognizer , timeBucketOfRequests , keptVersionCount )
249+ } else {
250+ // create a new application
251+ needTrainAndPublish = await this . createApplication ( currentApp , luBuildCore , recognizer , timeBucketOfRequests )
252+ }
252253
253- if ( needTrainAndPublish ) {
254- // train and publish application
255- await this . trainAndPublishApplication ( luBuildCore , recognizer , timeBucketOfRequests , isStaging )
256- }
254+ if ( needTrainAndPublish ) {
255+ // train and publish application
256+ await this . trainAndPublishApplication ( luBuildCore , recognizer , timeBucketOfRequests , isStaging )
257+ }
257258
258- // init settings asset
259- if ( settings === undefined ) {
260- const settingsPath = path . join ( path . dirname ( content . path ) , `luis.settings.${ suffix } .${ region } .json` )
261- settings = new Settings ( settingsPath , { } )
262- }
259+ // init settings asset
260+ if ( settings === undefined ) {
261+ const settingsPath = path . join ( path . dirname ( content . path ) , `luis.settings.${ suffix } .${ region } .json` )
262+ settings = new Settings ( settingsPath , { } )
263+ }
263264
264- // update settings asset
265- settings . luis [ content . name . split ( '.' ) . join ( '_' ) . replace ( / - / g, '_' ) ] = {
266- "appId" : recognizer . getAppId ( ) ,
267- "version" : recognizer . versionId
265+ // update settings asset
266+ settings . luis [ content . name . split ( '.' ) . join ( '_' ) . replace ( / - / g, '_' ) ] = {
267+ "appId" : recognizer . getAppId ( ) ,
268+ "version" : recognizer . versionId
269+ }
268270 }
269- }
270- } ) )
271- }
271+ } ) )
272+ }
272273
273- // write dialog assets
274- settingsAssets . push ( settings )
274+ // write dialog assets
275+ settingsAssets . push ( settings )
276+ }
277+ } catch ( error ) {
278+ throw ( new exception ( retCode . errorCode . LUIS_BUILD_FAILED , `Luis build failed: ${ error . message } ` ) )
275279 }
276280
277281 const settingsContent = this . generateDeclarativeAssets ( settingsAssets )
0 commit comments