Skip to content

Commit

Permalink
fix(developer): remove extra fatal exception
Browse files Browse the repository at this point in the history
- remove the fatal exception about a failed section compiler,
as it will always otherwise be propagated to the user

Fixes: #10894
  • Loading branch information
srl295 committed Mar 7, 2024
1 parent de50372 commit e77a495
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 0 additions & 4 deletions developer/src/kmc-ldml/src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,7 @@ export class LdmlKeyboardCompiler implements KeymanCompiler {
}
const sect = section.compile(globalSections);

/* c8 ignore next 7 */
if(!sect) {
// This should not happen -- validate() should have told us
// if something is going to fail to compile
this.callbacks.reportMessage(CompilerMessages.Fatal_SectionCompilerFailed({sect:section.id}));
passed = false;
continue;
}
Expand Down
8 changes: 3 additions & 5 deletions developer/src/kmc-ldml/src/compiler/messages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { util, CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m, CompilerMessageDef as def, CompilerMessageSpecWithException } from "@keymanapp/common-types";
import { util, CompilerErrorNamespace, CompilerErrorSeverity, CompilerMessageSpec as m, CompilerMessageDef as def } from "@keymanapp/common-types";
// const SevInfo = CompilerErrorSeverity.Info | CompilerErrorNamespace.LdmlKeyboardCompiler;
const SevHint = CompilerErrorSeverity.Hint | CompilerErrorNamespace.LdmlKeyboardCompiler;
const SevWarn = CompilerErrorSeverity.Warn | CompilerErrorNamespace.LdmlKeyboardCompiler;
const SevError = CompilerErrorSeverity.Error | CompilerErrorNamespace.LdmlKeyboardCompiler;
const SevFatal = CompilerErrorSeverity.Fatal | CompilerErrorNamespace.LdmlKeyboardCompiler;
// const SevFatal = CompilerErrorSeverity.Fatal | CompilerErrorNamespace.LdmlKeyboardCompiler;

/**
* @internal
Expand Down Expand Up @@ -59,9 +59,7 @@ export class CompilerMessages {
static Error_MustBeAtLeastOneLayerElement = () =>
m(this.ERROR_MustBeAtLeastOneLayerElement, `The source file must contain at least one layer element.`);

static FATAL_SectionCompilerFailed = SevFatal | 0x000F;
static Fatal_SectionCompilerFailed = (o:{sect: string}) =>
CompilerMessageSpecWithException(this.FATAL_SectionCompilerFailed, null, `The compiler for '${def(o.sect)}' failed unexpectedly.`);
// 0x000F - available

/** annotate the to= or id= entry */
private static outputOrKeyId(o:{output?: string, keyId?: string}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

<keys />

<!-- this is here because this test is used by test-compiler-e2e -->
<layers formId="us">
<layer id="base">
<row keys="a b c" />
</layer>
</layers>

<transforms type="simple">
<transformGroup>
<transform from="\u0127" to="x"/> <!-- fail: use \u{1234} instead -->
Expand Down
12 changes: 12 additions & 0 deletions developer/src/kmc-ldml/test/test-compiler-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ describe('compiler-tests', function() {
]);
assert.isNotNull(kmx);
});
it('should fail on extra escapes - sections/tran/fail-bad-tran-2.xml', async function() {
const inputFilename = makePathToFixture('sections/tran/fail-bad-tran-2.xml');
const kmx = await compileKeyboard(inputFilename, { ...compilerTestOptions, saveDebug: true, shouldAddCompilerVersion: false },
[
CompilerMessages.Error_InvalidQuadEscape({ cp: 295 }),
],
true, // validation should fail
[
// compiler messages (not reached, we've already failed)
]);
assert.isNull(kmx); // should fail post-validate
});
});
1 change: 1 addition & 0 deletions developer/src/kmc-ldml/test/test-tran.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ describe('tran', function () {
],
},
{
// also used in test-compiler-e2e.ts
subpath: `sections/tran/fail-bad-tran-2.xml`,
errors: [
CompilerMessages.Error_InvalidQuadEscape({ cp: 295 }),
Expand Down

0 comments on commit e77a495

Please sign in to comment.