Skip to content

Commit 38dff8a

Browse files
authored
Merge pull request #17 from LonoxX/develop
fix: handle note creation errors without aborting entire sync
2 parents 7927924 + 83a1b26 commit 38dff8a

2 files changed

Lines changed: 96 additions & 73 deletions

File tree

src/file-manager.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,13 @@ export class FileManager {
567567
private async ensureFolderExists(path: string): Promise<void> {
568568
const folder = this.app.vault.getAbstractFileByPath(path);
569569
if (!folder) {
570-
await this.app.vault.createFolder(path);
571-
this.noticeManager.debug(`Created folder: ${path}`);
570+
try {
571+
await this.app.vault.createFolder(path);
572+
this.noticeManager.debug(`Created folder: ${path}`);
573+
} catch (error) {
574+
// If creation is failed create again to ensure folder exists
575+
await this.app.vault.createFolder(path);
576+
}
572577
}
573578
}
574579

src/main.ts

Lines changed: 89 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export default class GitHubTrackerPlugin extends Plugin {
3737
"Error syncing issues and pull requests",
3838
error,
3939
);
40+
} finally {
41+
this.isSyncing = false;
4042
}
41-
this.isSyncing = false;
4243
}
4344

4445
async syncSingleRepository(repositoryName: string) {
@@ -161,8 +162,9 @@ export default class GitHubTrackerPlugin extends Plugin {
161162
`Error syncing repository ${repositoryName}`,
162163
error,
163164
);
165+
} finally {
166+
this.isSyncing = false;
164167
}
165-
this.isSyncing = false;
166168
}
167169

168170
async onload() {
@@ -324,45 +326,53 @@ export default class GitHubTrackerPlugin extends Plugin {
324326
const [owner, repoName] = repo.repository.split("/");
325327
if (!owner || !repoName) continue;
326328

327-
this.noticeManager.debug(
328-
`Fetching issues for ${repo.repository}`,
329-
);
330-
const allIssuesIncludingRecentlyClosed =
331-
await this.gitHubClient.fetchRepositoryIssues(
332-
owner,
333-
repoName,
334-
true,
335-
this.settings.cleanupClosedIssuesDays,
329+
try {
330+
this.noticeManager.debug(
331+
`Fetching issues for ${repo.repository}`,
332+
);
333+
const allIssuesIncludingRecentlyClosed =
334+
await this.gitHubClient.fetchRepositoryIssues(
335+
owner,
336+
repoName,
337+
true,
338+
this.settings.cleanupClosedIssuesDays,
339+
);
340+
341+
const openIssues = allIssuesIncludingRecentlyClosed.filter(
342+
(issue: { state: string }) => issue.state === "open",
336343
);
337344

338-
const openIssues = allIssuesIncludingRecentlyClosed.filter(
339-
(issue: { state: string }) => issue.state === "open",
340-
);
341-
342-
const filteredIssues = this.fileManager.filterIssues(
343-
repo,
344-
openIssues,
345-
);
345+
const filteredIssues = this.fileManager.filterIssues(
346+
repo,
347+
openIssues,
348+
);
346349

347-
this.noticeManager.debug(
348-
`Found ${allIssuesIncludingRecentlyClosed.length} total issues (${openIssues.length} open), ${filteredIssues.length} match filters for file creation/update`,
349-
);
350-
const currentIssueNumbers = new Set(
351-
filteredIssues.map((issue: { number: number }) =>
352-
issue.number.toString(),
353-
),
354-
);
350+
this.noticeManager.debug(
351+
`Found ${allIssuesIncludingRecentlyClosed.length} total issues (${openIssues.length} open), ${filteredIssues.length} match filters for file creation/update`,
352+
);
353+
const currentIssueNumbers = new Set(
354+
filteredIssues.map((issue: { number: number }) =>
355+
issue.number.toString(),
356+
),
357+
);
355358

356-
await this.fileManager.createIssueFiles(
357-
repo,
358-
filteredIssues,
359-
allIssuesIncludingRecentlyClosed,
360-
currentIssueNumbers,
361-
);
359+
await this.fileManager.createIssueFiles(
360+
repo,
361+
filteredIssues,
362+
allIssuesIncludingRecentlyClosed,
363+
currentIssueNumbers,
364+
);
362365

363-
this.noticeManager.debug(
364-
`Processed ${filteredIssues.length} open issues for ${repo.repository}`,
365-
);
366+
this.noticeManager.debug(
367+
`Processed ${filteredIssues.length} open issues for ${repo.repository}`,
368+
);
369+
} catch (repoError: unknown) {
370+
this.noticeManager.error(
371+
`Error processing issues for repository ${repo.repository}`,
372+
repoError,
373+
);
374+
// Continue with next repository
375+
}
366376
}
367377
} catch (error: unknown) {
368378
this.noticeManager.error("Error fetching GitHub issues", error);
@@ -387,48 +397,56 @@ export default class GitHubTrackerPlugin extends Plugin {
387397
const [owner, repoName] = repo.repository.split("/");
388398
if (!owner || !repoName) continue;
389399

390-
this.noticeManager.debug(
391-
`Fetching pull requests for ${repo.repository}`,
392-
);
393-
394-
const allPullRequestsIncludingRecentlyClosed =
395-
await this.gitHubClient.fetchRepositoryPullRequests(
396-
owner,
397-
repoName,
398-
true,
399-
this.settings.cleanupClosedIssuesDays,
400+
try {
401+
this.noticeManager.debug(
402+
`Fetching pull requests for ${repo.repository}`,
400403
);
401404

402-
const openPullRequests =
403-
allPullRequestsIncludingRecentlyClosed.filter(
404-
(pr: { state: string }) => pr.state === "open",
405+
const allPullRequestsIncludingRecentlyClosed =
406+
await this.gitHubClient.fetchRepositoryPullRequests(
407+
owner,
408+
repoName,
409+
true,
410+
this.settings.cleanupClosedIssuesDays,
411+
);
412+
413+
const openPullRequests =
414+
allPullRequestsIncludingRecentlyClosed.filter(
415+
(pr: { state: string }) => pr.state === "open",
416+
);
417+
418+
const filteredPRs = this.fileManager.filterPullRequests(
419+
repo,
420+
openPullRequests,
405421
);
406422

407-
const filteredPRs = this.fileManager.filterPullRequests(
408-
repo,
409-
openPullRequests,
410-
);
411-
412-
this.noticeManager.debug(
413-
`Found ${allPullRequestsIncludingRecentlyClosed.length} total pull requests (${openPullRequests.length} open), ${filteredPRs.length} match filters for file creation/update`,
414-
);
423+
this.noticeManager.debug(
424+
`Found ${allPullRequestsIncludingRecentlyClosed.length} total pull requests (${openPullRequests.length} open), ${filteredPRs.length} match filters for file creation/update`,
425+
);
415426

416-
const currentPRNumbers = new Set(
417-
filteredPRs.map((pr: { number: number }) =>
418-
pr.number.toString(),
419-
),
420-
);
427+
const currentPRNumbers = new Set(
428+
filteredPRs.map((pr: { number: number }) =>
429+
pr.number.toString(),
430+
),
431+
);
421432

422-
await this.fileManager.createPullRequestFiles(
423-
repo,
424-
filteredPRs,
425-
allPullRequestsIncludingRecentlyClosed,
426-
currentPRNumbers,
427-
);
433+
await this.fileManager.createPullRequestFiles(
434+
repo,
435+
filteredPRs,
436+
allPullRequestsIncludingRecentlyClosed,
437+
currentPRNumbers,
438+
);
428439

429-
this.noticeManager.debug(
430-
`Processed ${filteredPRs.length} open pull requests for ${repo.repository}`,
431-
);
440+
this.noticeManager.debug(
441+
`Processed ${filteredPRs.length} open pull requests for ${repo.repository}`,
442+
);
443+
} catch (repoError: unknown) {
444+
this.noticeManager.error(
445+
`Error processing pull requests for repository ${repo.repository}`,
446+
repoError,
447+
);
448+
// Continue with next repository
449+
}
432450
}
433451
} catch (error: unknown) {
434452
this.noticeManager.error(

0 commit comments

Comments
 (0)