API Bug: infinite loop possible with plugin settings
@EduardMe đang làm issue này rồi.
Từ ngày 7/11/2022.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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 ...
- Ngôn ngữ chính
- JavaScript
- Star
- 204
- Fork
- 82
- Merge trung bình
- 22 giờ 27 phút
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NotePlan/plugins
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Dashboard: Task "Comment" Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Tidy: Issue with plugin.json Đang mởbug
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
Tất cả issue của NotePlan/plugins
Issue tương tự
-
code-quality refactoring
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100