Skip to content

Commit dd5e966

Browse files
committed
refactor: format folder validation notice
1 parent 2769b04 commit dd5e966

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/engine/TemplateEngine.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,22 @@ export abstract class TemplateEngine extends QuickAddEngine {
273273
}
274274

275275
private showInvalidFolderNotice(error: Error): void {
276-
const message = error.message.replace(/^File name\b/, "Folder name");
277-
new Notice(message);
276+
new Notice(this.formatInvalidFolderMessage(error.message));
277+
}
278+
279+
private formatInvalidFolderMessage(message: string): string {
280+
const invalidCharsMatch = message.match(
281+
/^File name cannot contain any of the following characters:\s*(.+)$/u,
282+
);
283+
if (invalidCharsMatch?.[1]) {
284+
return `Folder name cannot contain any of the following characters: ${invalidCharsMatch[1]}`;
285+
}
286+
287+
if (message.startsWith("File name ")) {
288+
return `Folder name ${message.slice("File name ".length)}`;
289+
}
290+
291+
return "Invalid folder name.";
278292
}
279293

280294
private isPathAllowed(path: string, roots: string[]): boolean {

0 commit comments

Comments
 (0)