Fix error message with failed to resolve ohmurl

Issue: https://gitee.com/openharmony/developtools_ace_ets2bundle/issues/IB1OOI
Signed-off-by: ElevenDuan <duanshiyi1@huawei.com>
Change-Id: Idf6d35689828363a13dd74ddb3dcbb5dcb1af396
This commit is contained in:
ElevenDuan 2024-11-03 15:48:18 +08:00
parent 998205b1e1
commit ca989db558
5 changed files with 46 additions and 12 deletions

View File

@ -96,7 +96,6 @@ export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: O
}
let unixFilePath: string = toUnixPath(filePath);
unixFilePath = unixFilePath.substring(0, filePath.lastIndexOf('.')); // remove extension
let projectFilePath: string = unixFilePath.replace(toUnixPath(pkgPath), '');
// case1: /entry/src/main/ets/xxx/yyy
// case2: /entry/src/ohosTest/ets/xxx/yyy
// case3: /node_modules/xxx/yyy
@ -105,12 +104,14 @@ export function getNormalizedOhmUrlByFilepath(filePath: string, projectConfig: O
// case6: /library/index.ts
// ---> @normalized:N&<moduleName>&<bunldName>&<packageName>/entry/ets/xxx/yyy&<version>
let pkgInfo = projectConfig.pkgContextInfo[pkgName];
if (pkgInfo === undefined) {
if (!pkgInfo || !pkgPath) {
logger.error(red, 'ArkTS:ERROR Failed to resolve OhmUrl.\n' +
`Error Message: Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".\n` +
`Solutions: > Check whether the module which ${filePath} belongs to is correctly configured.` +
`Solutions: > Check whether the "${pkgName}" module which ${filePath} belongs to is correctly configured.` +
'> Check the corresponding file name is correct(including case-sensitivity).', reset);
return filePath;
}
let projectFilePath: string = unixFilePath.replace(toUnixPath(pkgPath), '');
let recordName = `${pkgInfo.bundleName}&${pkgName}${projectFilePath}&${pkgInfo.version}`;
if (isRecordName) {
// record name style: <bunldName>&<packageName>/entry/ets/xxx/yyy&<version>

View File

@ -205,10 +205,14 @@ export class ModuleMode extends CommonMode {
let moduleId: string = entryObj[key];
let moduleInfo: Object = rollupObject.getModuleInfo(moduleId);
if (!moduleInfo) {
this.logger.error(red, `ArkTS:INTERNAL ERROR: Failed to find module info.\n` +
`Error Message: Failed to find module info with '${moduleId}' from the context information.`, reset);
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: Failed to find module info.\n` +
`Error Message: Failed to find module info with '${moduleId}' from the context information.`);
}
let metaInfo: Object = moduleInfo.meta;
if (!metaInfo) {
this.throwArkTsCompilerError(`ArkTS:INTERNAL ERROR: Failed to find meta info.\n` +
`Error Message: Failed to find meta info with '${moduleId}' from the module info.`);
}
const pkgParams = {
pkgName: metaInfo.pkgName,
pkgPath: metaInfo.pkgPath,

View File

@ -115,7 +115,15 @@ class ModuleModeMock extends ModuleMode {
for (const key in entryObj) {
let moduleId: string = entryObj[key];
let moduleInfo: Object = rollupObject.getModuleInfo(moduleId);
if (!moduleInfo) {
this.throwArkTsCompilerError(red, `ArkTS:INTERNAL ERROR: Failed to find module info.\n` +
`Error Message: Failed to find module info with '${moduleId}' from the context information.`, reset);
}
let metaInfo: Object = moduleInfo.meta;
if (!metaInfo) {
this.throwArkTsCompilerError(red, `ArkTS:INTERNAL ERROR: Failed to find meta info.\n` +
`Error Message: Failed to find meta info with '${moduleId}' from the module info.`, reset);
}
const pkgParams = {
pkgName: metaInfo.pkgName,
pkgPath: metaInfo.pkgPath,

View File

@ -1792,9 +1792,7 @@ mocha.describe('test module_mode file api', function () {
SourceMapGenerator.initInstance(this.rollup);
this.rollup.mockCompileContextInfo();
const moduleMode = new ModuleModeMock(this.rollup);
const logger = moduleMode.logger;
const loggerStub = sinon.stub(logger, 'error');
const stub = sinon.stub(moduleMode, 'throwArkTsCompilerError');
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
const entryObjName:string = 'test';
@ -1806,10 +1804,10 @@ mocha.describe('test module_mode file api', function () {
} catch (e) {
}
expect(loggerStub.getCall(0).calledWith(red, `ArkTS:INTERNAL ERROR: Failed to find module info.\n` +
`Error Message: Failed to find module info with '${moduleId}' from the context information.`, reset)).to.be.true;
expect(stub.calledWithMatch(`ArkTS:INTERNAL ERROR: Failed to find module info.\n` +
`Error Message: Failed to find module info with '${moduleId}' from the context information.`)).to.be.true;
loggerStub.restore();
stub.restore();
SourceMapGenerator.cleanSourceMapObject();
});
@ -1832,4 +1830,27 @@ mocha.describe('test module_mode file api', function () {
expect(moduleMode.checkGenerateCompileContextInfo(this.rollup) === true).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('18-13: test generateCompileContext has not exist meta info', function () {
this.rollup.build();
this.rollup.mockCompileContextInfo();
const moduleMode = new ModuleModeMock(this.rollup);
const stub = sinon.stub(moduleMode, 'throwArkTsCompilerError');
const entryObjName:string = 'noMetaInfo';
const moduleId:string = 'd:/test.ets';
moduleMode.projectConfig.entryObj[entryObjName]=moduleId;
moduleMode.projectConfig.cardEntryObj[entryObjName]=moduleId;
const moduleInfo = {
id: moduleId,
meta: null
}
this.rollup.moduleInfos.push(moduleInfo);
try {
moduleMode.generateCompileContextInfoMock(this.rollup);
} catch (e) {
}
expect(stub.calledWithMatch(`ArkTS:INTERNAL ERROR: Failed to find meta info.\n` +
`Error Message: Failed to find meta info with '${moduleId}' from the module info.`)).to.be.true;
stub.restore();
});
});

View File

@ -896,7 +896,7 @@ mocha.describe('generate ohmUrl', function () {
}
expect(loggerStub.calledWith(red, 'ArkTS:ERROR Failed to resolve OhmUrl.\n' +
`Error Message: Failed to get a resolved OhmUrl for "${filePath}" imported by "${importerFile}".\n` +
`Solutions: > Check whether the module which ${filePath} belongs to is correctly configured.` +
`Solutions: > Check whether the "json5" module which ${filePath} belongs to is correctly configured.` +
'> Check the corresponding file name is correct(including case-sensitivity).', reset)).to.be.true;
loggerStub.restore();
});