Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(developer): handle missing Name element for File element in package compiler #11352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions developer/src/kmc-package/src/compiler/kmp-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ export class KmpCompiler implements KeymanCompiler {
// note: we don't emit fileType as that is not permitted in kmp.json
};
});
if(!kmp.files.reduce((result: boolean, file) => {
if(!file.name) {
// as the filename field is missing or blank, we'll try with the description instead
this.callbacks.reportMessage(CompilerMessages.Error_FileRecordIsMissingName({description: file.description ?? '(no description)'}));
return false;
}
return result;
}, true)) {
return null;
}
}
kmp.files = kmp.files ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,9 @@ export class CompilerMessages {
static ERROR_InvalidPackageFile = SevError | 0x001E;
static Error_InvalidPackageFile = (o:{e:any}) => m(this.ERROR_InvalidPackageFile,
`Package source file is invalid: ${(o.e ?? 'unknown error').toString()}`);

static ERROR_FileRecordIsMissingName = SevError | 0x001F;
static Error_FileRecordIsMissingName = (o:{description:string}) => m(this.ERROR_FileRecordIsMissingName,
`File record in the package with description '${o.description}' is missing a filename.`);
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PackageKeyboardTargetValidator {
// package also includes the .js
const targets = KeymanTargets.keymanTargetsFromString(targetsText, {expandTargets: true});
if(targets.some(target => KeymanTargets.TouchKeymanTargets.includes(target))) {
if(!kmp.files.find(file => this.callbacks.path.basename(file.name, '.js') == keyboard.id)) {
if(!kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', '.js') == keyboard.id)) {
// .js version of the keyboard is not found, warn
this.callbacks.reportMessage(CompilerMessages.Warn_JsKeyboardFileIsMissing({id: keyboard.id}));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ export class PackageMetadataCollector {
): KeyboardMetadata {

let isJavascript = false;
let file = kmp.files.find(file => this.callbacks.path.basename(file.name, KeymanFileTypes.Binary.Keyboard) == keyboard.id);
let file = kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', KeymanFileTypes.Binary.Keyboard) == keyboard.id);
if(!file) {
isJavascript = true;
file = kmp.files.find(file => this.callbacks.path.basename(file.name, KeymanFileTypes.Binary.WebKeyboard) == keyboard.id);
file = kmp.files.find(file => this.callbacks.path.basename(file.name ?? '', KeymanFileTypes.Binary.WebKeyboard) == keyboard.id);
if(!file) {
this.callbacks.reportMessage(CompilerMessages.Error_KeyboardContentFileNotFound({id:keyboard.id}));
return null;
}
}

if(!file.name) {
this.callbacks.reportMessage(CompilerMessages.Error_FileRecordIsMissingName({description: file.description ?? '(no description)'}));
return null;
}

const filename = this.callbacks.resolveFilename(kpsFilename, file.name);
if(!this.callbacks.fs.existsSync(filename)) {
this.callbacks.reportMessage(CompilerMessages.Error_KeyboardFileNotFound({filename}));
Expand Down
Loading