Skip to content

Commit 1899e17

Browse files
CopilotMicroFish91
andcommitted
Fix trim() error on undefined values in template providers
Co-authored-by: MicroFish91 <40250218+MicroFish91@users.noreply.github.com>
1 parent 0c2c84f commit 1899e17

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/templates/TemplateProviderBase.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ export abstract class TemplateProviderBase implements Disposable {
106106
}
107107

108108
public async getBackupTemplateVersion(): Promise<string> {
109-
return (await AzExtFsExtra.readFile(await this.getBackupVersionPath())).toString().trim();
109+
const versionPath = await this.getBackupVersionPath();
110+
if (await AzExtFsExtra.pathExists(versionPath)) {
111+
const content = await AzExtFsExtra.readFile(versionPath);
112+
return content ? content.toString().trim() : '';
113+
}
114+
return '';
110115
}
111116

112117
public async updateBackupTemplateVersion(version: string): Promise<void> {

src/templates/java/JavaTemplateProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export class JavaTemplateProvider extends ScriptTemplateProvider {
3737
public async getLatestTemplateVersion(): Promise<string> {
3838
this.validateGradleProject();
3939
const pomPath: string = path.join(this.getProjectPath(), pomXmlFileName);
40-
const pomContents: string = (await AzExtFsExtra.readFile(pomPath)).toString();
40+
const pomFileContent = await AzExtFsExtra.readFile(pomPath);
41+
if (!pomFileContent) {
42+
throw new Error(localize('failedToReadPom', 'Failed to read pom.xml file.'));
43+
}
44+
const pomContents: string = pomFileContent.toString();
4145
const match: RegExpMatchArray | null = pomContents.match(/<azure.functions.maven.plugin.version>(.*)<\/azure.functions.maven.plugin.version>/i);
4246
if (!match) {
4347
throw new Error(localize('failedToDetectPluginVersion', 'Failed to detect Azure Functions maven plugin version.'));

0 commit comments

Comments
 (0)