Skip to content

Commit

Permalink
chore: use Result instead of panicking in a mapping operation
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSimplyKyle committed Oct 2, 2023
1 parent b2e4b2e commit 69aff41
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
5 changes: 2 additions & 3 deletions app/lib/api/gen/bridge_definitions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// coverage:ignore-file
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.81.0.
// Generated by `flutter_rust_bridge`@ 1.82.1.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const

import 'dart:convert';
Expand Down Expand Up @@ -50,7 +49,7 @@ abstract class Native {

FlutterRustBridgeTaskConstMeta get kGetAccountStorageConstMeta;

String? getSkinFilePath({required MinecraftSkin skin, dynamic hint});
String getSkinFilePath({required MinecraftSkin skin, dynamic hint});

FlutterRustBridgeTaskConstMeta get kGetSkinFilePathConstMeta;

Expand Down
27 changes: 19 additions & 8 deletions app/lib/api/gen/bridge_generated.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// coverage:ignore-file
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.81.0.
// Generated by `flutter_rust_bridge`@ 1.82.1.
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const

import "bridge_definitions.dart";
Expand Down Expand Up @@ -31,6 +30,7 @@ class NativeImpl implements Native {
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_setup_logger(port_),
parseSuccessData: _wire2api_unit,
parseErrorData: _wire2api_FrbAnyhowException,
constMeta: kSetupLoggerConstMeta,
argValues: [],
hint: hint,
Expand All @@ -47,6 +47,7 @@ class NativeImpl implements Native {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_launch_vanilla(port_),
parseSuccessData: _wire2api_progress,
parseErrorData: null,
constMeta: kLaunchVanillaConstMeta,
argValues: [],
hint: hint,
Expand All @@ -63,6 +64,7 @@ class NativeImpl implements Native {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_launch_forge(port_),
parseSuccessData: _wire2api_progress,
parseErrorData: null,
constMeta: kLaunchForgeConstMeta,
argValues: [],
hint: hint,
Expand All @@ -79,6 +81,7 @@ class NativeImpl implements Native {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_launch_quilt(port_),
parseSuccessData: _wire2api_progress,
parseErrorData: null,
constMeta: kLaunchQuiltConstMeta,
argValues: [],
hint: hint,
Expand All @@ -95,6 +98,7 @@ class NativeImpl implements Native {
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_fetch_state(port_),
parseSuccessData: _wire2api_download_state,
parseErrorData: null,
constMeta: kFetchStateConstMeta,
argValues: [],
hint: hint,
Expand All @@ -112,6 +116,7 @@ class NativeImpl implements Native {
return _platform.executeNormal(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_write_state(port_, arg0),
parseSuccessData: _wire2api_unit,
parseErrorData: null,
constMeta: kWriteStateConstMeta,
argValues: [s],
hint: hint,
Expand All @@ -129,6 +134,7 @@ class NativeImpl implements Native {
return _platform.executeSync(FlutterRustBridgeSyncTask(
callFfi: () => _platform.inner.wire_get_ui_layout_storage(arg0),
parseSuccessData: _wire2api_ui_layout_value,
parseErrorData: null,
constMeta: kGetUiLayoutStorageConstMeta,
argValues: [key],
hint: hint,
Expand All @@ -148,6 +154,7 @@ class NativeImpl implements Native {
callFfi: (port_) =>
_platform.inner.wire_set_ui_layout_storage(port_, arg0),
parseSuccessData: _wire2api_unit,
parseErrorData: _wire2api_FrbAnyhowException,
constMeta: kSetUiLayoutStorageConstMeta,
argValues: [value],
hint: hint,
Expand All @@ -166,6 +173,7 @@ class NativeImpl implements Native {
return _platform.executeSync(FlutterRustBridgeSyncTask(
callFfi: () => _platform.inner.wire_get_account_storage(arg0),
parseSuccessData: _wire2api_account_storage_value,
parseErrorData: null,
constMeta: kGetAccountStorageConstMeta,
argValues: [key],
hint: hint,
Expand All @@ -178,11 +186,12 @@ class NativeImpl implements Native {
argNames: ["key"],
);

String? getSkinFilePath({required MinecraftSkin skin, dynamic hint}) {
String getSkinFilePath({required MinecraftSkin skin, dynamic hint}) {
var arg0 = _platform.api2wire_box_autoadd_minecraft_skin(skin);
return _platform.executeSync(FlutterRustBridgeSyncTask(
callFfi: () => _platform.inner.wire_get_skin_file_path(arg0),
parseSuccessData: _wire2api_opt_String,
parseSuccessData: _wire2api_String,
parseErrorData: null,
constMeta: kGetSkinFilePathConstMeta,
argValues: [skin],
hint: hint,
Expand All @@ -201,6 +210,7 @@ class NativeImpl implements Native {
callFfi: (port_) =>
_platform.inner.wire_remove_minecraft_account(port_, arg0),
parseSuccessData: _wire2api_unit,
parseErrorData: _wire2api_FrbAnyhowException,
constMeta: kRemoveMinecraftAccountConstMeta,
argValues: [uuid],
hint: hint,
Expand All @@ -217,6 +227,7 @@ class NativeImpl implements Native {
return _platform.executeStream(FlutterRustBridgeTask(
callFfi: (port_) => _platform.inner.wire_minecraft_login_flow(port_),
parseSuccessData: _wire2api_login_flow_event,
parseErrorData: null,
constMeta: kMinecraftLoginFlowConstMeta,
argValues: [],
hint: hint,
Expand All @@ -234,6 +245,10 @@ class NativeImpl implements Native {
}
// Section: wire2api

FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) {
return FrbAnyhowException(raw as String);
}

String _wire2api_String(dynamic raw) {
return raw as String;
}
Expand Down Expand Up @@ -408,10 +423,6 @@ class NativeImpl implements Native {
return MinecraftSkinVariant.values[raw as int];
}

String? _wire2api_opt_String(dynamic raw) {
return raw == null ? null : _wire2api_String(raw);
}

UuidValue? _wire2api_opt_Uuid(dynamic raw) {
return raw == null ? null : _wire2api_Uuid(raw);
}
Expand Down
14 changes: 5 additions & 9 deletions app/native/src/api/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ pub async fn process_forge(
.iter()
.map(|x| {
convert_maven_to_path(x, Some(&folder))
.expect("failed to convert processor classpath maven to path")
.context("failed to convert processor classpath maven to path")
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;
processor_classpath.push(jar);
let minecraft_jar;
let side;
Expand Down Expand Up @@ -285,14 +285,10 @@ pub async fn process_forge(
)
.into_iter()
.map(|x| {
if x.starts_with('[') {
convert_maven_to_path(&x, Some(&folder))
.expect("failed to convert [] types maven into path")
} else {
x
}
convert_maven_to_path(&x, Some(&folder))
.context("failed to convert [] types maven into path")
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;
let mut all = Vec::new();
all.push(String::from("-cp"));
all.push(processor_classpath.join(":"));
Expand Down
30 changes: 15 additions & 15 deletions app/native/src/bridge_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
clippy::too_many_arguments
)]
// AUTO GENERATED FILE, DO NOT EDIT.
// Generated by `flutter_rust_bridge`@ 1.81.0.
// Generated by `flutter_rust_bridge`@ 1.82.1.

use crate::api::*;
use core::panic::UnwindSafe;
Expand All @@ -23,7 +23,7 @@ use std::sync::Arc;
// Section: wire functions

fn wire_setup_logger_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "setup_logger",
port: Some(port_),
Expand All @@ -33,7 +33,7 @@ fn wire_setup_logger_impl(port_: MessagePort) {
)
}
fn wire_launch_vanilla_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "launch_vanilla",
port: Some(port_),
Expand All @@ -43,7 +43,7 @@ fn wire_launch_vanilla_impl(port_: MessagePort) {
)
}
fn wire_launch_forge_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "launch_forge",
port: Some(port_),
Expand All @@ -53,7 +53,7 @@ fn wire_launch_forge_impl(port_: MessagePort) {
)
}
fn wire_launch_quilt_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "launch_quilt",
port: Some(port_),
Expand All @@ -63,25 +63,25 @@ fn wire_launch_quilt_impl(port_: MessagePort) {
)
}
fn wire_fetch_state_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, DownloadState>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, DownloadState, _>(
WrapInfo {
debug_name: "fetch_state",
port: Some(port_),
mode: FfiCallMode::Normal,
},
move || move |task_callback| Ok(fetch_state()),
move || move |task_callback| Result::<_, ()>::Ok(fetch_state()),
)
}
fn wire_write_state_impl(port_: MessagePort, s: impl Wire2Api<DownloadState> + UnwindSafe) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "write_state",
port: Some(port_),
mode: FfiCallMode::Normal,
},
move || {
let api_s = s.wire2api();
move |task_callback| Ok(write_state(api_s))
move |task_callback| Result::<_, ()>::Ok(write_state(api_s))
},
)
}
Expand All @@ -96,15 +96,15 @@ fn wire_get_ui_layout_storage_impl(
},
move || {
let api_key = key.wire2api();
Ok(get_ui_layout_storage(api_key))
Result::<_, ()>::Ok(get_ui_layout_storage(api_key))
},
)
}
fn wire_set_ui_layout_storage_impl(
port_: MessagePort,
value: impl Wire2Api<UILayoutValue> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "set_ui_layout_storage",
port: Some(port_),
Expand All @@ -127,7 +127,7 @@ fn wire_get_account_storage_impl(
},
move || {
let api_key = key.wire2api();
Ok(get_account_storage(api_key))
Result::<_, ()>::Ok(get_account_storage(api_key))
},
)
}
Expand All @@ -142,15 +142,15 @@ fn wire_get_skin_file_path_impl(
},
move || {
let api_skin = skin.wire2api();
Ok(get_skin_file_path(api_skin))
Result::<_, ()>::Ok(get_skin_file_path(api_skin))
},
)
}
fn wire_remove_minecraft_account_impl(
port_: MessagePort,
uuid: impl Wire2Api<uuid::Uuid> + UnwindSafe,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "remove_minecraft_account",
port: Some(port_),
Expand All @@ -163,7 +163,7 @@ fn wire_remove_minecraft_account_impl(
)
}
fn wire_minecraft_login_flow_impl(port_: MessagePort) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, ()>(
FLUTTER_RUST_BRIDGE_HANDLER.wrap::<_, _, _, (), _>(
WrapInfo {
debug_name: "minecraft_login_flow",
port: Some(port_),
Expand Down
7 changes: 4 additions & 3 deletions app/test/dialog/setup/login_account_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class MockNativeImpl extends _i1.Mock implements _i9.NativeImpl {
),
) as _i7.AccountStorageValue);
@override
String? getSkinFilePath({
String getSkinFilePath({
required _i7.MinecraftSkin? skin,
dynamic hint,
}) =>
Expand All @@ -507,8 +507,9 @@ class MockNativeImpl extends _i1.Mock implements _i9.NativeImpl {
#hint: hint,
},
),
returnValueForMissingStub: null,
) as String?);
returnValue: '',
returnValueForMissingStub: '',
) as String);
@override
_i8.Future<void> removeMinecraftAccount({
required _i4.UuidValue? uuid,
Expand Down

0 comments on commit 69aff41

Please sign in to comment.