Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated output is not always the same. Possible race condition? #1002

Closed
AlexDochioiu opened this issue Oct 31, 2023 · 4 comments
Closed
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@AlexDochioiu
Copy link

Describe the bug
The .freezed.dart file generated seems to keep on oscillating between two "versions" when running dart run build_runner build --delete-conflicting-outputs. Sometimes I get a result, other times I get a different one, despite the lack of changes in the source file.

To Reproduce

@freezed
class DetailedWallet with _$DetailedWallet {
  const DetailedWallet._();

  const factory DetailedWallet.data({
    required DetailedWalletDto dto,
    required String name,
    required String uid,
    required String stakingAddress,
    required String receiveAddress,
    required SelectedNetwork network,
    required bool isReadOnly,
    required Pfp pfp,
  }) = DetailedWalletData;

  const factory DetailedWallet.error({
    required String name,
    required String uid,
    required String stakingAddress,
    required String receiveAddress,
    required SelectedNetwork network,
    required bool isReadOnly,
    required Pfp pfp,
    required ApiError error,
  }) = DetailedWalletError;

  const factory DetailedWallet.loading({
    required String name,
    required String uid,
    required String stakingAddress,
    required String receiveAddress,
    required SelectedNetwork network,
    required bool isReadOnly,
    required Pfp pfp,
  }) = DetailedWalleLoading;
}

The following are other freezed classes: DetailedWalletDto, SelectedNetwork, Pfp, ApiError. I will only include ApiError since it may be relevant.

@freezed
class ApiError extends Error with _$ApiError {
  ApiError._();

  factory ApiError.jsonParsing(String jsonString) = JsonParsingError;

  factory ApiError.dartHttpClient(Object innerError) = DartHttpClientError;

  factory ApiError.generic() = GenericError;

  factory ApiError.nonSuccessCode({
    required int errorCode,
    required String? rawErrorString,
    required BackendErrorResponse backendErrorResponse,
  }) = NonSuccessCodeError;

  String get displayErrorMessage => maybeMap(
        orElse: () => "Something went wrong",
        dartHttpClient: (_) => "Please check your internet connection",
        nonSuccessCode: (p) => p.backendErrorResponse.errorMessage ?? "Something went wrong",
      );

// @override
// StackTrace? get stackTrace => super.stackTrace;
}

@freezed
class BackendErrorResponse with _$BackendErrorResponse {
  const BackendErrorResponse._();

  const factory BackendErrorResponse({
    @JsonKey(name: "errorTitle") String? errorTitle,
    @JsonKey(name: "errorMessage") String? errorMessage,
    @JsonKey(name: "devErrorMessage") String? devErrorMessage,
  }) = _BackendErrorResponse;

  factory BackendErrorResponse.fromJson(Map<String, dynamic> json) => _$BackendErrorResponseFromJson(json);
}

Expected behavior

the freezed class for DetailedWallet stays unchanged.

image image

Additional info
ApiError is built in another flutter module/dependency. When running the build_runner for the module containing DetailedWallet, the freezed for ApiError is already built and imported (so the issue cannot be caused by the DetailedWallet freezed class being built before the ApiError one)

@AlexDochioiu
Copy link
Author

Some deps versions:

  freezed:
    dependency: "direct dev"
    description:
      name: freezed
      sha256: "21bf2825311de65501d22e563e3d7605dff57fb5e6da982db785ae5372ff018a"
      url: "https://pub.dev"
    source: hosted
    version: "2.4.5"
  freezed_annotation:
    dependency: "direct main"
    description:
      name: freezed_annotation
      sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d
      url: "https://pub.dev"
    source: hosted
    version: "2.4.1"
  _fe_analyzer_shared:
    dependency: transitive
    description:
      name: _fe_analyzer_shared
      sha256: eb376e9acf6938204f90eb3b1f00b578640d3188b4c8a8ec054f9f479af8d051
      url: "https://pub.dev"
    source: hosted
    version: "64.0.0"
  analyzer:
    dependency: transitive
    description:
      name: analyzer
      sha256: "69f54f967773f6c26c7dcb13e93d7ccee8b17a641689da39e878d5cf13b06893"
      url: "https://pub.dev"
    source: hosted
    version: "6.2.0"
Flutter 3.16.0-0.3.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 476aa717cd (11 days ago) • 2023-10-19 20:10:52 -0500
Engine • revision 91cde06da0
Tools • Dart 3.2.0 (build 3.2.0-210.3.beta) • DevTools 2.28.1

@rrousselGit
Copy link
Owner

Hard to say. I'd need steps to reproduce

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Oct 31, 2023
@seanny421
Copy link

I seem to also have this problem across different machines, my colleagues g files are slightly different, like using (as num).toInt() as opposed to my generated files which simply use as int

@rrousselGit
Copy link
Owner

To me it sounds like you and your colleague are using two different versions of the same package, so the generated code is different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants