API Bug: infinite loop possible with plugin settings
@EduardMe 已经在做这个了。
开始于 2022年11月7日。
评估
这个 Issue 还没有评估数据。
描述
I thought I had a bright idea, Eduard. But it landed up causing an infinite loop, confirmed by looking the logs.
Aim: While developing complex new plugin commands, we often create smaller commands to test various bits, and we've taken to prefixing them with test:. These shouldn't be needed by ordinary users, unless hunting down bugs with the dev. So wouldn't it be nice to hide them from the menus and command bar unless they're in DEBUG logging mode?
So I borrowed some of @dwertheimer's helper code to produce this, which should only fire when user changes settings. It checks to see if they're not in DEBUG mode, and if so hides the test:* commands:
const pluginID = "jgclark.Summaries"
export async function onSettingsUpdated(): Promise<void> {
try {
logDebug(pluginID, 'starting onSettingsUpdated')
// See if we need to hide or unhide the test: commands in this plugin, depending whether _logLevel is DEBUG or not
// Get the commands' details
const initialPluginJson = await getPluginJson(pluginID)
const initialSettings = await getSettings(pluginID) ?? `{".logLevel": "INFO"}`
// $FlowFixMe[incompatible-type]
const logLevel = initialSettings["_logLevel"]
logInfo('onSettingsUpdated', `Starting with _logLevel ${logLevel}`)
let updatedPluginJson = initialPluginJson
if (initialPluginJson) {
const commands = updatedPluginJson['plugin.commands']
let testCommands = commands.filter((command) => {
const start = command.name.slice(0, 4)
return start === 'test'
})
logInfo('onSettingsUpdated', `- found ${testCommands.length} test commands`)
// WARNING: savePluginJson() causes an infinite loop!
// WARNING: So all these lines are commented out.
// if (logLevel === 'DEBUG') {
// for (let command of testCommands) {
// updatedPluginJson = updateJSONForFunctionNamed(updatedPluginJson, command, false)
// }
// clo(updatedPluginJson, `updatedPluginJson after unhiding:`)
// }
// else {
// for (let command of testCommands) {
// updatedPluginJson = updateJSONForFunctionNamed(updatedPluginJson, command, true)
// }
// }
// logDebug('onSettingsUpdated', `- before savePluginJson ...`)
// await savePluginJson(pluginJson['plugin.id'], updatedPluginJson) // helper that calls saveJSON()
// logDebug('onSettingsUpdated', ` - NOT CALLED OTHERWISE AN INFINITE LOOP!`)
}
}
catch (error) {
logError('onSettingsUpdated', error.message)
}
}
David and I think this is an NP bug. It is calling the onSettingsUpdated() function when any JSON file is written anywhere using the saveJSON method. I don't think that should be the case. Only when DataStore.settings is changed should that "hook" be called.
BTW this is an example of the potential issues implementing triggers/hooks ...
- 主要语言
- JavaScript
- 星标
- 204
- 派生
- 82
- 平均合并
- 22 小时 27 分钟
- 30 天内合并 PR
- 3
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NotePlan/plugins 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
-
bug
难度 4/5 3-5 天 新手友好度 48/100
-
难度 5/5 一周以上 新手友好度 35/100
-
bug
-
bug
难度 3/5 1-2 天 新手友好度 38/100
相似的 Issue
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
难度 2/5 1-3 小时 新手友好度 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100