fix: defer config error toast to session.created for TUI readiness (#286)
* fix: defer config error toast to session.created for TUI readiness Removed showToast calls from loadConfigFromPath() function. Error notifications were not visible during plugin initialization because the TUI was not ready yet. Changes: - Removed immediate showToast calls from validation error handler - Removed immediate showToast calls from file load error handler - Errors are still captured via addConfigLoadError() for later display - auto-update-checker hook will display errors via showConfigErrorsIfAny() after session.created event This ensures error messages are displayed when the TUI is fully ready and able to render them properly. 🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) * fix: await config error toast before showing startup toast Ensure config errors are awaited and displayed before the startup spinner toast is shown. Changed showConfigErrorsIfAny(ctx).catch(() => {}) to await showConfigErrorsIfAny(ctx) to guarantee proper error handling order. 🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -34,12 +34,12 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat
|
|||||||
|
|
||||||
hasChecked = true
|
hasChecked = true
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
const cachedVersion = getCachedVersion()
|
const cachedVersion = getCachedVersion()
|
||||||
const localDevVersion = getLocalDevVersion(ctx.directory)
|
const localDevVersion = getLocalDevVersion(ctx.directory)
|
||||||
const displayVersion = localDevVersion ?? cachedVersion
|
const displayVersion = localDevVersion ?? cachedVersion
|
||||||
|
|
||||||
showConfigErrorsIfAny(ctx).catch(() => {})
|
await showConfigErrorsIfAny(ctx)
|
||||||
|
|
||||||
if (localDevVersion) {
|
if (localDevVersion) {
|
||||||
if (showStartupToast) {
|
if (showStartupToast) {
|
||||||
|
|||||||
27
src/index.ts
27
src/index.ts
@@ -129,20 +129,6 @@ function loadConfigFromPath(configPath: string, ctx: any): OhMyOpenCodeConfig |
|
|||||||
const errorMsg = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`).join(", ");
|
const errorMsg = result.error.issues.map(i => `${i.path.join(".")}: ${i.message}`).join(", ");
|
||||||
log(`Config validation error in ${configPath}:`, result.error.issues);
|
log(`Config validation error in ${configPath}:`, result.error.issues);
|
||||||
addConfigLoadError({ path: configPath, error: `Validation error: ${errorMsg}` });
|
addConfigLoadError({ path: configPath, error: `Validation error: ${errorMsg}` });
|
||||||
|
|
||||||
const errorList = result.error.issues
|
|
||||||
.map(issue => `• ${issue.path.join(".")}: ${issue.message}`)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
ctx.client.tui.showToast({
|
|
||||||
body: {
|
|
||||||
title: "❌ OhMyOpenCode: Config Validation Failed",
|
|
||||||
message: `Failed to load ${configPath}\n\nValidation errors:\n${errorList}\n\nConfig will be ignored. Please fix the errors above.`,
|
|
||||||
variant: "error" as const,
|
|
||||||
duration: 10000,
|
|
||||||
},
|
|
||||||
}).catch(() => {});
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,19 +139,6 @@ function loadConfigFromPath(configPath: string, ctx: any): OhMyOpenCodeConfig |
|
|||||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||||
log(`Error loading config from ${configPath}:`, err);
|
log(`Error loading config from ${configPath}:`, err);
|
||||||
addConfigLoadError({ path: configPath, error: errorMsg });
|
addConfigLoadError({ path: configPath, error: errorMsg });
|
||||||
|
|
||||||
const hint = err instanceof SyntaxError
|
|
||||||
? "\n\nHint: Check for syntax errors in your JSON file (missing commas, quotes, brackets, etc.)"
|
|
||||||
: "";
|
|
||||||
|
|
||||||
ctx.client.tui.showToast({
|
|
||||||
body: {
|
|
||||||
title: "❌ OhMyOpenCode: Config Load Failed",
|
|
||||||
message: `Failed to load ${configPath}\n\nError: ${errorMsg}${hint}\n\nConfig will be ignored. Please fix the error above.`,
|
|
||||||
variant: "error" as const,
|
|
||||||
duration: 10000,
|
|
||||||
},
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user