Files
cutdex/lib/errors/app_failure.dart
T
lingjhf abc1868550
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

105 lines
2.7 KiB
Dart

/// Stable application error identities; independent of interface language.
enum AppErrorCode {
operationFailed,
agentRestartHint,
loadRecentProjectsFailed,
loadProjectsFailed,
projectAccessFailed,
projectLocationNotWritable,
projectLocationUnavailable,
projectLocationCreateFailed,
projectMissingDirectory,
recentProjectSaveFailed,
lastProjectSaveFailed,
enterProjectName,
projectSwitched,
notLocalMedia,
revealMediaFailed,
openMatchingProject,
openTimelineFailed,
projectMismatch,
projectAlreadyExists,
openProjectFirst,
localFilesOnly,
foldersUnsupported,
mediaImportCancelled,
fileAccessFailed,
registerMediaFailed,
mediaNoLongerExists,
mediaNoTracks,
invalidMediaDuration,
mediaInfoUnsupported,
mediaInfoFailed,
saveTimelineFailed,
projectNameInvalid,
projectLocationDefaultUnavailable,
chooseProjectLocation,
timelineMissing,
timelineInUse,
timelineHasBackgroundTasks,
timelineRequired,
projectSessionClosed,
timelineSessionClosed,
mediaReadFailed,
mediaImportFailed,
unsupportedMediaType,
mediaNoVideoTracks,
mediaDurationOutOfRange,
resourceChecksumFailed,
enterName,
agentLocationUnavailable,
agentLocationBusy,
startBackgroundRemovalFailed,
subtitleEngineUnavailable,
timelineChanged,
resourceDownloadHttpFailed,
diagnostic,
}
/// An error remains structured until the presentation layer chooses its wording.
final class AppFailure {
const AppFailure(this.code, {this.diagnostic, this.httpStatusCode});
final AppErrorCode code;
final String? diagnostic;
final int? httpStatusCode;
bool get requiresProjectLocation => switch (code) {
AppErrorCode.projectLocationNotWritable ||
AppErrorCode.projectLocationUnavailable ||
AppErrorCode.projectLocationCreateFailed ||
AppErrorCode.projectLocationDefaultUnavailable ||
AppErrorCode.chooseProjectLocation => true,
_ => false,
};
@override
bool operator ==(Object other) =>
other is AppFailure &&
code == other.code &&
diagnostic == other.diagnostic &&
httpStatusCode == other.httpStatusCode;
@override
int get hashCode => Object.hash(code, diagnostic, httpStatusCode);
@override
String toString() => diagnostic ?? code.name;
}
/// Keeps existing StateError catch boundaries while carrying a stable identity.
final class AppException extends StateError {
AppException(AppErrorCode code, {String? diagnostic, int? httpStatusCode})
: this.fromFailure(
AppFailure(
code,
diagnostic: diagnostic,
httpStatusCode: httpStatusCode,
),
);
AppException.fromFailure(this.failure) : super(failure.toString());
final AppFailure failure;
}