Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 33c378b

Browse files
authored
optimize error msg text when error comes from imported files (#659)
* export lu content id when throw errors in luMerge.js * optimize
1 parent 620e269 commit 33c378b

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/lu/src/parser/lu/luMerger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ const parseLuFile = async function(luOb, log, luis_culture) {
517517
try {
518518
parsedContent = await parseFileContents.parseFile(luOb.content, log, luis_culture);
519519
} catch (err) {
520+
err.source = luOb.id;
520521
throw(err);
521522
}
522523
if (!parsedContent) {

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export class Builder {
4747
result = await LuisBuilderVerbose.build(luFiles, true, culture)
4848
fileContent = result.parseToLuContent()
4949
} catch (err) {
50-
err.text = `Invalid LU file ${file}: ${err.text}`
50+
if (err.source) {
51+
err.text = `Invalid LU file ${err.source}: ${err.text}`
52+
} else {
53+
err.text = `Invalid LU file ${file}: ${err.text}`
54+
}
5155
throw(new exception(retCode.errorCode.INVALID_INPUT_FILE, err.text))
5256
}
5357

packages/luis/test/commands/luis/build.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ describe('luis:build cli parameters test', () => {
5656
test
5757
.stdout()
5858
.stderr()
59-
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/bad3.lu')}`, '--botName', 'Contoso'])
59+
.command(['luis:build', '--authoringKey', uuidv1(), '--in', `${path.join(__dirname, './../../fixtures/testcases/invalid_import_file.lu')}`, '--botName', 'Contoso'])
6060
.it('displays an error if error occurs in parsing lu content', ctx => {
6161
expect(ctx.stderr).to.contain('Invalid LU file')
62+
expect(ctx.stderr).to.contain('bad3.lu')
6263
expect(ctx.stderr).to.contain('[ERROR] line 4:0 - line 4:16: Invalid intent body line, did you miss \'-\' at line begin')
6364
})
6465
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# greeting
2+
- hi
3+
- hello
4+
5+
[import lu file with error](bad3.lu)

0 commit comments

Comments
 (0)