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

fix: capture ProcessException when hook generation fails due to dart pub get #1242

Open
alestiago opened this issue Feb 5, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@alestiago
Copy link
Collaborator

alestiago commented Feb 5, 2024

Description

Running hooks using the Mason API throws a ProcessException if Dart executable is not installed.

Steps To Reproduce

  1. Run a Mason Generator:
final generator = await MasonGenerator.fromBundle(myBundle);
await generator.hooks.preGen(vars: {'name':'Dash'});
  1. See error:
ProcessException: No such file or directory
  Command: /bin/sh -c 'dart' 'pub' 'get'

Expected Behavior

I would expect the error to be captured, it is currently not being captured.

I would expect a better error message that outlined the issue comes from Mason itself (since it is running the dart pub get internally) with a verbose description on how to resolve.

Additional Context

@alestiago alestiago added the bug Something isn't working label Feb 5, 2024
@alestiago alestiago changed the title fix: fix: capture ProcessException when hook generation fails Feb 5, 2024
@alestiago alestiago changed the title fix: capture ProcessException when hook generation fails fix: capture ProcessException when hook generation fails due to dart pub get Feb 5, 2024
@felangel
Copy link
Owner

Hi @alestiago 👋
Can you elaborate? It looks like the error is being captured in

throw HookDependencyInstallFailure(
.

Can you share an example of what you'd expect the output to be? Thanks!

@felangel felangel added the waiting for response Waiting for additional information label Jun 28, 2024
@alestiago
Copy link
Collaborator Author

alestiago commented Jun 28, 2024

Hi @felangel , this is quite old already and I don't have all the context I had back then. In a nutshell, the error was never a HookDependencyInstallFailure and it was reached in a CI environment, where if you tried running a Dart program with the sample code given it would fail with the ProcessException if Dart was configured in a particular way.


It looks like the error is being captured in line 222

I did notice the HookDependencyInstallFailure, but the reported error was never of such type, but a ProcessException instead. Might well be because the error code condition was not reached due to the thrown ProcessException.

Consider:

import 'dart:io';

Future<void> main() async {
  final result = await Process.run('not-a-command', ['pub', 'get']);

  if (result.exitCode != 0) {
    throw Exception('Something went wrong!);
  }
}

Running the above throws "ProcessException: No such file or directory" not the exception. Whereas:

import 'dart:io';

Future<void> main() async {
  try {
    await Process.run('not-a-command', ['pub', 'get']);
    // ...
  } catch (e) {
    throw Exception('Something went wrong!');
  }
}

Does capture the ProcessExcpetion and throws an Exception instead.


Can you share an example of what you'd expect the output to be?

I would expect the output to be an error message with a verbose explanation that includes information about what the program was trying to do, and a recommendation to solve the failure. So for example, something along the lines:

  try {
    await Process.run('not-a-command', ['pub', 'get']);
    // ...
  } catch (e) {
    throw HookDependencyInstallFailure('''
      Failed to install hook dependencies in $workingDirectory. 
      Make sure you have the Dart SDK installed and that the 'pub' command is available in your PATH.
     ''');
  }

@alestiago alestiago removed the waiting for response Waiting for additional information label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants