From f654f5a05ea675ec8dd7278f8861417d3274af79 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 24 Oct 2026 16:47:02 +0200 Subject: [PATCH] fix: stop error notices when toggling Progress Properties and the Kanban helper Each toggle reconciles both automators with the settings, so the one that was already on got attached again and attach() logged 'a ProgressProperties automator is already attached.' Attaching an attached automator is now a no-op. The notice also read '(ERROR)' because LogManager.logWarning fanned out to each logger's logError. Warnings now go to logWarning and read '(WARNING)'. The docs that described that quirk are updated. --- .../onFileModifyAutomatorManager.test.ts | 46 +++++++++++++++++++ .../onFileModifyAutomatorManager.ts | 8 ++-- src/logger/logManager.ts | 2 +- tests/obsidian-stub.ts | 14 ++++++ .../docs/cookbook/kanban-status-sync.md | 2 +- .../src/content/docs/guides/kanban-helper.md | 4 +- website/src/content/docs/help/faq.md | 4 -- .../src/content/docs/help/troubleshooting.md | 6 +-- website/src/content/docs/reference/notices.md | 10 ++-- 9 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 src/automators/onFileModifyAutomatorManager.test.ts diff --git a/src/automators/onFileModifyAutomatorManager.test.ts b/src/automators/onFileModifyAutomatorManager.test.ts new file mode 100644 index 0000000..bcc6449 --- /dev/null +++ b/src/automators/onFileModifyAutomatorManager.test.ts @@ -0,0 +1,46 @@ +import {afterEach, beforeEach, describe, expect, it} from "vitest"; +import {Notice} from "../../tests/obsidian-stub"; +import {log} from "../logger/logManager"; +import {GuiLogger} from "../logger/guiLogger"; +import {OnFileModifyAutomatorManager} from "./onFileModifyAutomatorManager"; +import {OnModifyAutomatorType} from "./onFileModifyAutomators/onModifyAutomatorType"; +import type {IOnFileModifyAutomator} from "./onFileModifyAutomators/IOnFileModifyAutomator"; + +const resetLoggers = () => { + (log.constructor as unknown as {loggers: unknown[]}).loggers = []; + Notice.messages = []; +}; + +const automator = (type: OnModifyAutomatorType) => ({type, onFileModify: async () => {}}) as unknown as IOnFileModifyAutomator; + +describe("OnFileModifyAutomatorManager.attach", () => { + beforeEach(() => { + resetLoggers(); + log.register(new GuiLogger({} as never)); + }); + afterEach(resetLoggers); + + it("treats attaching an already attached automator as a no-op, without a notice", () => { + const manager = new OnFileModifyAutomatorManager({app: {}} as never); + + manager.attach(automator(OnModifyAutomatorType.ProgressProperties)); + manager.attach(automator(OnModifyAutomatorType.KanbanHelper)); + manager.attach(automator(OnModifyAutomatorType.ProgressProperties)); + + expect(Notice.messages).toEqual([]); + }); +}); + +describe("log.logWarning", () => { + beforeEach(() => { + resetLoggers(); + log.register(new GuiLogger({} as never)); + }); + afterEach(resetLoggers); + + it("reports warnings at warning level", () => { + log.logWarning("file Board not found."); + + expect(Notice.messages).toEqual(["MetaEdit: (WARNING) file Board not found."]); + }); +}); diff --git a/src/automators/onFileModifyAutomatorManager.ts b/src/automators/onFileModifyAutomatorManager.ts index 4aa7dbd..6ced702 100644 --- a/src/automators/onFileModifyAutomatorManager.ts +++ b/src/automators/onFileModifyAutomatorManager.ts @@ -32,11 +32,9 @@ export class OnFileModifyAutomatorManager implements IAutomatorManager { } attach(automator: IOnFileModifyAutomator): IAutomatorManager { - const isExist = this.automators.some(tAuto => tAuto.type === automator.type); - if (isExist) { - log.logWarning(`a ${automator.type} automator is already attached.`); - return this; - } + // toggleAutomators() reconciles every automator with the settings, so the + // one that is already on gets attached again whenever another is toggled. + if (this.automators.some(tAuto => tAuto.type === automator.type)) return this; this.automators.push(automator); return this; diff --git a/src/logger/logManager.ts b/src/logger/logManager.ts index f5878ef..e3ce132 100644 --- a/src/logger/logManager.ts +++ b/src/logger/logManager.ts @@ -15,7 +15,7 @@ class LogManager { } logWarning(message: string) { - LogManager.loggers.forEach(logger => logger.logError(message)); + LogManager.loggers.forEach(logger => logger.logWarning(message)); } logMessage(message: string) { diff --git a/tests/obsidian-stub.ts b/tests/obsidian-stub.ts index 9db7476..40c0c6b 100644 --- a/tests/obsidian-stub.ts +++ b/tests/obsidian-stub.ts @@ -28,6 +28,20 @@ export function createTFile(path: string): obsidian.TFile { return new TFile(path) as unknown as obsidian.TFile; } +export function debounce(cb: (...args: T) => unknown, timeout = 0) { + let timer: ReturnType | undefined; + const debounced = (...args: T) => { + clearTimeout(timer); + timer = setTimeout(() => cb(...args), timeout); + return debounced; + }; + debounced.cancel = () => { + clearTimeout(timer); + return debounced; + }; + return debounced; +} + export class Notice { static messages: string[] = []; diff --git a/website/src/content/docs/cookbook/kanban-status-sync.md b/website/src/content/docs/cookbook/kanban-status-sync.md index bcf4688..4be5689 100644 --- a/website/src/content/docs/cookbook/kanban-status-sync.md +++ b/website/src/content/docs/cookbook/kanban-status-sync.md @@ -107,7 +107,7 @@ Drag a card, wait a few seconds, and the table regroups. The same property also | Symptom | Cause and fix | | --- | --- | -| Notice: `MetaEdit: (ERROR) 'status' not found in "Website relaunch" (Kanban board 'Projects').` | The linked note lacks the property. The helper updates properties but never creates them - add `status` to the note first (step 2). | +| Notice: `MetaEdit: (WARNING) 'status' not found in "Website relaunch" (Kanban board 'Projects').` | The linked note lacks the property. The helper updates properties but never creates them - add `status` to the note first (step 2). | | Nothing happens after a drag | Wait for the 5-second debounce; it resets while the board keeps changing. The helper only reacts to modifications made through Obsidian. | | One specific card never syncs | Only the leading link of a top-level card line counts (`- [ ] [[Note]] ...`). Trailing links such as Kanban date links, links in the card text, and indented sub-items are ignored. A card sitting above the first lane heading has no lane and is skipped. If several notes share the card's bare name and Obsidian cannot resolve the link, the helper skips it rather than guess. | | Board stopped syncing after you renamed it | Boards are matched by file basename, and the stored row keeps the old name. Remove the row and re-add the renamed board. If the board file is gone, its "Possible values" cell shows `FILE NOT FOUND`. | diff --git a/website/src/content/docs/guides/kanban-helper.md b/website/src/content/docs/guides/kanban-helper.md index 2e3ba29..ec16d77 100644 --- a/website/src/content/docs/guides/kanban-helper.md +++ b/website/src/content/docs/guides/kanban-helper.md @@ -69,10 +69,10 @@ The helper shares its trigger pipeline with Progress Properties: modify event on When a card's note lacks the configured property, MetaEdit shows a notice for that card: ```text -MetaEdit: (ERROR) 'status' not found in "Dune review" (Kanban board 'Editorial calendar'). +MetaEdit: (WARNING) 'status' not found in "Dune review" (Kanban board 'Editorial calendar'). ``` -This is a warning - nothing is broken - but it appears with the `MetaEdit: (ERROR)` prefix anyway; that is a known quirk of how MetaEdit surfaces warnings. Fix it by adding the property to the note. See the [notices reference](/reference/notices/) for every message MetaEdit can show. +This is a warning - nothing is broken. Fix it by adding the property to the note. See the [notices reference](/reference/notices/) for every message MetaEdit can show. ## Caveats diff --git a/website/src/content/docs/help/faq.md b/website/src/content/docs/help/faq.md index adcc35a..600e2ee 100644 --- a/website/src/content/docs/help/faq.md +++ b/website/src/content/docs/help/faq.md @@ -51,10 +51,6 @@ Yes. Everywhere MetaEdit matches names - Auto Properties, "Edit Meta menu" hidde In your vault at `.obsidian/plugins/metaedit/data.json`. Settings sync with the vault if you sync that folder. The [settings reference](/reference/settings/) documents every field. -## Why does a warning say "(ERROR)"? - -A known logging quirk: MetaEdit's warnings are routed through the error channel, so warning notices read `MetaEdit: (ERROR) ...`. Judge the message by its text, not the label - a warning like the Kanban helper's "property not found" notice does not mean data was lost. See the [notices reference](/reference/notices/). - ## Where did the body-tag delete and transform actions go? Removed in 1.9.0. Body tags have no `key:` line, so those two actions could not target the right text safely. Renaming a tag and editing the last segment of a nested tag remain, and frontmatter `tags` editing is unaffected. See [what's new in 1.9.0](/getting-started/whats-new/) and [edit tags](/guides/edit-tags/). diff --git a/website/src/content/docs/help/troubleshooting.md b/website/src/content/docs/help/troubleshooting.md index 1194fbc..1c5ce40 100644 --- a/website/src/content/docs/help/troubleshooting.md +++ b/website/src/content/docs/help/troubleshooting.md @@ -67,7 +67,7 @@ See [Progress Properties](/guides/progress-properties/) and the [Kanban Board He - **Heading-less cards have no lane.** A card above the first heading is skipped because there is no lane name to write. - **Ambiguous basenames are refused.** If several notes share the linked basename and Obsidian's cache cannot resolve which one is meant, the helper skips that card rather than write to the wrong note. - **A renamed board file breaks the configuration.** Boards are matched by file basename and the stored name does not follow a rename; the settings row then shows "FILE NOT FOUND" in its "Possible values" column. Re-add the board under its new name. -- **The linked note must already have the property.** If it is missing you get a notice per affected card: `MetaEdit: (ERROR) '' not found in "" (Kanban board '').` +- **The linked note must already have the property.** If it is missing you get a notice per affected card: `MetaEdit: (WARNING) '' not found in "" (Kanban board '').` **Fix:** structure cards as `- [ ] [[Note]]` under a heading, keep board file names stable, and add the configured property to each linked note. Details in the [Kanban Board Helper guide](/guides/kanban-helper/). @@ -117,10 +117,6 @@ Several MetaEdit messages go to the console only: - **macOS:** press `Cmd+Option+I`, then open the Console tab. - **Mobile:** there is no built-in console. On Android you can attach Chrome's remote debugger via `chrome://inspect` with USB debugging enabled; iOS does not expose one. -:::note[Warnings are labeled "(ERROR)"] -Due to a logging quirk, MetaEdit warnings surface prefixed `MetaEdit: (ERROR) ...`. The label does not mean data was lost - read the message itself. See the [FAQ](/help/faq/#why-does-a-warning-say-error) and the [notices reference](/reference/notices/). -::: - ## File a good issue If your problem is not covered here, open an issue on [GitHub](https://github.com/chhoumann/MetaEdit/issues) and include: diff --git a/website/src/content/docs/reference/notices.md b/website/src/content/docs/reference/notices.md index 3f1b971..cbdb756 100644 --- a/website/src/content/docs/reference/notices.md +++ b/website/src/content/docs/reference/notices.md @@ -7,8 +7,8 @@ sidebar: This page lists every user-visible notice MetaEdit can show, with the exact text (placeholders in `{braces}`), the situation that triggers it, and what to do. Use your browser's find-in-page to jump to the message you saw. For symptoms without a notice, start at [troubleshooting](/help/troubleshooting/). -:::note[The "MetaEdit: (ERROR)" prefix on warnings] -Messages routed through MetaEdit's warning channel are displayed with the prefix `MetaEdit: (ERROR)` - in the notice popup and in the developer console. That is a logging quirk (warnings fan out to the error channel), not a crash. The Kanban Board Helper's "not found" message below is the most common example. +:::note[The "(WARNING)" and "(ERROR)" prefixes] +Notices from MetaEdit's logger start with `MetaEdit: (WARNING)` or `MetaEdit: (ERROR)`. A warning means MetaEdit skipped something it could not do, such as updating a property the note does not have. No data is lost. Older versions labeled warnings `(ERROR)` too. ::: ## Editing properties @@ -81,12 +81,12 @@ See [Auto Properties](/guides/auto-properties/). ## Progress Properties and Kanban Board Helper -See [Progress Properties](/guides/progress-properties/) and the [Kanban Board Helper](/guides/kanban-helper/). These carry the `MetaEdit: (ERROR)` prefix described above. +See [Progress Properties](/guides/progress-properties/) and the [Kanban Board Helper](/guides/kanban-helper/). These carry the prefixes described above. | Notice | When it appears | What to do | | --- | --- | --- | -| `MetaEdit: (ERROR) '{property}' not found in "{note}" (Kanban board '{board}').` | A card changed lanes, but the linked note does not contain the configured property. The helper only updates existing properties - it never creates them. | Add the property to the note (any value), then move the card again. | -| `MetaEdit: (ERROR) file {board} not found.` | A configured board file no longer exists - the settings panel also shows `FILE NOT FOUND` in its "Possible values" column. Boards are matched by file basename, so renaming the board file breaks the row. | Remove the row and re-add the board under its new name. | +| `MetaEdit: (WARNING) '{property}' not found in "{note}" (Kanban board '{board}').` | A card changed lanes, but the linked note does not contain the configured property. The helper only updates existing properties - it never creates them. | Add the property to the note (any value), then move the card again. | +| `MetaEdit: (WARNING) file {board} not found.` | A configured board file no longer exists - the settings panel also shows `FILE NOT FOUND` in its "Possible values" column. Boards are matched by file basename, so renaming the board file breaks the row. | Remove the row and re-add the board under its new name. | | `MetaEdit: (ERROR) {message}` | A Progress Properties update failed while writing task counts. | Check the note's frontmatter parses (Obsidian shows invalid frontmatter in the editor), then modify the note again to re-trigger the count. | ## Reserved property names