Files
cutdex/lib/errors/app_failure.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

104 lines
2.6 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,
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;
}