Skip to content

Commit

Permalink
feat(task): 繰り返しタスクファイルに記載された繰り返しパターンが不正値の場合はできるだけエラーとして表示する
Browse files Browse the repository at this point in the history
  • Loading branch information
tadashi-aikawa committed Nov 4, 2024
1 parent 97cadd5 commit 4003970
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"typescript": "^5.6.3"
},
"dependencies": {
"@tadashi-aikawa/silhouette-core": "npm:@jsr/tadashi-aikawa__silhouette-core@^1.2.0",
"@tadashi-aikawa/silhouette-core": "npm:@jsr/tadashi-aikawa__silhouette-core@^1.3.0",
"owlelia": "^0.48.1"
}
}
}

2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createCommands(

taskService.insertTasksToDailyNote(date).then((err) => {
if (err) {
new Notice(`[Error] ${err.name}: ${err.message}`, 0);
new Notice(`[エラー] ${err.name}\n\n ${err.message}`, 0);
return;
}

Expand Down
42 changes: 32 additions & 10 deletions src/repository/TaskRepositoryImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,43 @@ export class TaskRepositoryImpl implements TaskRepository {
loadRepetitionTasks(): AsyncResult<RepetitionTask[], BaseError> {
// TODO: 起点日登録ミスは警告したい
return fromPromise(
this.appHelper.loadFile(this.repetitionTasksFilePath).then((tasksStr) =>
tasksStr
this.appHelper.loadFile(this.repetitionTasksFilePath).then((tasksStr) => {
const recordOrErrors = tasksStr
.split("\n")
.filter((line) => !line.startsWith("//") && line.trim() !== "")
.map((line) => line.split(","))
.filter((cols) => cols.length > 1)
.map(([name, repetitions, baseDate]) => {
return RepetitionTask.of({
name: name.replace(/^[ \t]+/, ""),
repetitions: Repetition.fromRepetitionsStr(repetitions),
baseDate: baseDate ? DateTime.of(baseDate) : undefined,
indent: name.match("^[ \t]+")?.at(0) ?? "",
});
}),
),
const [reps, errs] =
Repetition.fromRepetitionsStr(repetitions).unwrap();
if (errs) {
return { errors: errs };
}
return {
record: RepetitionTask.of({
name: name.replace(/^[ \t]+/, ""),
repetitions: reps,
baseDate: baseDate ? DateTime.of(baseDate) : undefined,
indent: name.match("^[ \t]+")?.at(0) ?? "",
}),
};
});

const errors = recordOrErrors
.map((x) => x.errors)
.filter((x) => x !== undefined)
.flat();
if (errors.length > 0) {
throw {
name: "繰り返しタスクの読み込み時にパースエラーが発生",
message: errors.map((x) => `* ${x.message}`).join("\n"),
};
}

return recordOrErrors
.map((x) => x.record)
.filter((x) => x !== undefined);
}),
);
}

Expand Down

0 comments on commit 4003970

Please sign in to comment.