Skip to content

Improve error message for routing #2267

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkgs/code_assets/lib/src/code_assets/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ ValidationErrors _validateFile(
}) {
final errors = <String>[];
if (mustBeAbsolute && !uri.isAbsolute) {
errors.add('$name (${uri.toFilePath()}) must be an absolute path.');
errors.add('$name at ${uri.toFilePath()} must be an absolute path.');
}
if (mustExist && !File.fromUri(uri).existsSync()) {
errors.add('$name (${uri.toFilePath()}) does not exist as a file.');
errors.add('$name at ${uri.toFilePath()} does not exist as a file.');
}
return errors;
}
10 changes: 6 additions & 4 deletions pkgs/data_assets/lib/src/data_assets/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ List<String> _validateHookInput(List<EncodedAsset> assets) {
final dataAsset = DataAsset.fromEncoded(asset);
errors.addAll(
_validateFile(
'LinkInput.assets.data asset "${dataAsset.id}" file',
'LinkInput.assets.data asset "${dataAsset.id}"',
dataAsset.file,
),
);
Expand Down Expand Up @@ -98,7 +98,7 @@ void _validateDataAsset(
errors.add('More than one data asset with same "${dataAsset.name}" name.');
}
final file = dataAsset.file;
errors.addAll(_validateFile('Data asset ${dataAsset.name} file', file));
errors.addAll(_validateFile('Data asset "${dataAsset.name}"', file));
}

ValidationErrors _validateDataAssetSyntax(EncodedAsset encodedAsset) {
Expand Down Expand Up @@ -129,10 +129,12 @@ ValidationErrors _validateFile(
}) {
final errors = <String>[];
if (mustBeAbsolute && !uri.isAbsolute) {
errors.add('$name (${uri.toFilePath()}) must be an absolute path.');
errors.add(
'$name points to "${uri.toFilePath()}", which must be an absolute path.',
);
}
if (mustExist && !File.fromUri(uri).existsSync()) {
errors.add('$name (${uri.toFilePath()}) does not exist as a file.');
errors.add('$name points to "${uri.toFilePath()}", which does not exist.');
}
return errors;
}
23 changes: 20 additions & 3 deletions pkgs/hooks/lib/src/validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,26 @@ class ProtocolBase {
final errors = <String>[];
if (!input.config.linkingEnabled) {
if (output.assets.encodedAssetsForLinking.isNotEmpty) {
const error =
'BuildOutput.assets_for_linking is not empty while '
'BuildInput.config.linkingEnabled is false';
final error =
'''
`BuildOutput.assets_for_linking` is not empty while `BuildInput.config.linkingEnabled` is `false`.

The assets ${output.assets.encodedAssetsForLinking} where sent to linking, but should either be bundled with the app or linked only when linking is enabled.

This might be caused by writing something like

```
routing: ToLinkHook(input.packageName),
```

Try writing this instead:

```
routing: input.config.linkingEnabled
? ToLinkHook(input.packageName)
: ToAppBundle(),
```
''';
errors.add(error);
}
}
Expand Down
Loading