linshenkx/prompt-optimizer · error · EvaluationValidationError
Workspace prompt must not be empty.
Error message
Workspace prompt must not be empty.
What it means
Catch-all OptimizationError at the end of optimizeMessage: every error thrown in the method (request validation, model lookup, template resolution, LLM call, response validation) is re-wrapped as 'Message optimization failed: <original message>'. The original cause survives only inside the message string.
Source
Thrown at packages/core/src/services/evaluation/service.ts:470
private validateRequest(request: EvaluationRequest): void {
if (!request.evaluationModelKey?.trim()) {
throw new EvaluationValidationError('Evaluation model key must not be empty.');
}
if (!request.mode) {
throw new EvaluationValidationError('Evaluation mode configuration must not be empty.');
}
if (!request.mode.functionMode) {
throw new EvaluationValidationError('Function mode must not be empty.');
}
if (!request.mode.subMode) {
throw new EvaluationValidationError('Sub mode must not be empty.');
}
switch (request.type) {
case 'result':
if (!request.target?.workspacePrompt?.trim()) {
throw new EvaluationValidationError('Workspace prompt must not be empty.');
}
this.validateTestCase(request.testCase, 'Result evaluation test case');
this.validateSnapshot(request.snapshot, 'Result evaluation snapshot');
if (request.snapshot.testCaseId !== request.testCase.id) {
throw new EvaluationValidationError(
'Result evaluation snapshot testCaseId must match testCase.id.'
);
}
if (this.isImageText2ImageMode(request) && !this.hasSnapshotOutputMedia(request.snapshot)) {
throw new EvaluationValidationError(
'Image result evaluation requires at least one output image evidence item.'
);
}
break;
case 'compare':
if (!request.target?.workspacePrompt?.trim()) {
throw new EvaluationValidationError('Workspace prompt must not be empty.');View on GitHub (pinned to 3e677b1d9f)
Solutions
- Extract the text after 'Message optimization failed: ' and fix the root cause it names (401 → credentials, timeout → retry, template/model → config).
- Pre-validate the request (ids, messages, modelKey) so only genuine runtime failures reach this wrapper.
- Log the full error object, not just the message, to preserve stack context.
- Retry transient causes (network/timeout) with a single retry and backoff.
Example fix
// before
catch (e) { showError(String(e)); }
// after
catch (e) {
const msg = e instanceof Error ? e.message : String(e);
const cause = msg.startsWith('Message optimization failed:') ? msg.split(':').slice(1).join(':').trim() : msg;
if (/timeout|network|fetch/i.test(cause)) return retryLater();
showError(cause);
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate everything the service checks internally
const ok = req.selectedMessageId?.trim()
&& req.messages?.length
&& req.messages.some(m => m.id === req.selectedMessageId && m.content?.trim())
&& await modelManager.getModel(req.modelKey);
if (!ok) throw new Error('Request invalid'); Type guard
function isOptimizationError(e: unknown): e is OptimizationError { return e instanceof OptimizationError; }
function rootCause(e: unknown): string {
const m = e instanceof Error ? e.message : String(e);
return m.replace(/^Message optimization failed:\s*/, '');
} Try / catch
try { return await svc.optimizeMessage(req); }
catch (e) { const cause = rootCause(e); if (/timeout|network|fetch/i.test(cause)) return retryWithBackoff(req); showError(cause); } Prevention
- Pre-validate ids, messages, content, and model to keep runtime errors out of the wrapper
- Retry only transient causes identified from the embedded message
- Preserve full error objects in logs for stack traces
When it happens
Trigger: Any mid-pipeline failure in the message-optimization flow — provider auth errors, network failures, empty LLM responses, missing templates — all rethrown under this wrapper.
Common situations: Invalid/expired API keys, offline clients, template manager misconfiguration, or the inner validation errors above when callers don't pre-validate; the flattened message hides the error class, complicating diagnostics.
Related errors
- Evaluation mode configuration must not be empty.
- DATA_ERROR_CODES.ELECTRON_API_UNAVAILABLE
- Data must be an object
- "data" property is missing or not an object
- Unrecognized data structure
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/9cf4973c75f64fe0.
Report an issue: GitHub.