Files
pipelines/app/lib/core/error_advice.dart
T
alan e72bee3faa First run: empty states with a next step, harness setup instead of errors
- One shared EmptyState (icon on a tonal disc, title, one line, primary
  action) that follows the design tokens; used by Runs (Start your first
  run), Pipelines (Browse templates), Schedules and the chat list (Start a
  chat).
- Chat on a server without an agent harness showed "Bad state: No saved
  machine is connected.": the federated list now keeps the server's own
  refusal, treats an omitted empty list as no chats, and the list shows a
  "Set up an agent" state with the harness setup command and Refresh. New
  chat shows the same step instead of a form that can only be refused.
- A run that fails because no harness CLI exists names the setup command
  beside the raw reason; error advice gains a noHarness kind.
- Templates opened before the app connected stayed on "Not connected";
  it now reads again when the connection arrives. The Pipelines empty state
  links to Templates, which had no entry point in the UI.
- The first-launch walkthrough waits briefly for the connection, so a
  connected web app is no longer told to connect; the empty-server check
  treats omitted lists and no chat harness as empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:29:23 +00:00

92 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async' show TimeoutException;
import 'error_reason.dart';
import 'transport/connection_state.dart';
/// The common kinds of failure an operator can act on.
enum ErrorAdviceKind {
notConnected,
serverTooOld,
permission,
timeout,
/// The server has no agent harness to run a chat or a stage with: a setup
/// step on the server, not a failure of this app.
noHarness,
}
/// What to do about a failure, as one sentence, and the raw detail it came
/// from (kept available behind the sentence, never replaced by it).
typedef ErrorAdvice = ({ErrorAdviceKind kind, String sentence, String detail});
/// Maps a request failure (an exception or the message a controller kept) to
/// a sentence saying what to do, or null when it is none of the common kinds
/// (the raw message then stands on its own).
ErrorAdvice? errorAdvice(Object? error) {
if (error == null) return null;
final detail = describeErrorReason(error, fallback: 'Unknown error');
final kind = errorAdviceKind(error);
if (kind == null) return null;
return (kind: kind, sentence: errorAdviceSentence(kind), detail: detail);
}
/// The failure's kind, from its type or its words.
ErrorAdviceKind? errorAdviceKind(Object error) {
if (error is NotConnectedError) return ErrorAdviceKind.notConnected;
if (error is TimeoutException) return ErrorAdviceKind.timeout;
if (error is ProtocolError && error.code == 'elevation_required') {
return ErrorAdviceKind.permission;
}
final text = '$error'.toLowerCase();
if (needsHarnessSetup(text)) return ErrorAdviceKind.noHarness;
if (_tooOld.hasMatch(text)) return ErrorAdviceKind.serverTooOld;
if (_permission.hasMatch(text)) return ErrorAdviceKind.permission;
if (_timeout.hasMatch(text)) return ErrorAdviceKind.timeout;
if (_notConnected.hasMatch(text)) return ErrorAdviceKind.notConnected;
return null;
}
String errorAdviceSentence(ErrorAdviceKind kind) => switch (kind) {
ErrorAdviceKind.notConnected =>
'Not connected to the server. Check the connection in Settings, then '
'try again.',
ErrorAdviceKind.serverTooOld =>
'This server is too old for this feature. Update the Pipelines server, '
'then try again.',
ErrorAdviceKind.permission =>
'The server refused this for lack of permission. Sign in again in '
'Settings › Connection, then try again.',
ErrorAdviceKind.timeout =>
'The server did not answer in time. Check the connection, then try '
'again.',
ErrorAdviceKind.noHarness =>
'No agent harness is set up on the server yet. In a terminal on the '
'server, run `pipelines harness setup <agent>` (claude, codex, '
'opencode or pi), then try again.',
};
/// Whether [error] says the server has no usable agent harness: chat is not
/// configured, or a stage could not start its harness's CLI. Such a server is
/// new, not broken, so callers show the setup step instead of an error.
bool needsHarnessSetup(Object? error) =>
error != null && _noHarness.hasMatch('$error'.toLowerCase());
final _noHarness = RegExp(
r'chat is not configured|harness unreachable|'
r'cannot run the selected \w+ cli',
);
final _tooOld = RegExp(
r'unknown (command|message|request)|unsupported (command|message|request)',
);
final _permission = RegExp(
r'permission denied|unauthori[sz]ed|forbidden|not signed in|'
r'sign-in required|authentication (required|failed)|elevation_required|'
r'\b401\b|\b403\b',
);
final _timeout = RegExp(r'timed out|timeout');
final _notConnected = RegExp(
r'not connected|connection (closed|replaced|refused|lost|failed)|'
r'websocket|failed host lookup|network is unreachable|no saved machine',
);