Skip to content

Commit

Permalink
Merge remote-tracking branch 'google/master' into google#780
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker1024 committed Mar 8, 2021
2 parents 35745a7 + 3bf4564 commit 3c6d717
Show file tree
Hide file tree
Showing 55 changed files with 337 additions and 183 deletions.
62 changes: 31 additions & 31 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with package:mono_repo v3.4.6
# Created with package:mono_repo v3.4.7
name: Dart CI
on:
push:
Expand Down Expand Up @@ -27,32 +27,32 @@ jobs:
restore-keys: |
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
uses: actions/checkout@v2
- name: mono_repo self validate
run: pub global activate mono_repo 3.4.6
run: pub global activate mono_repo 3.4.7
- name: mono_repo self validate
run: pub global run mono_repo generate --validate
job_002:
name: "analyzer_and_format; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
name: "analyzer_and_format; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_annotation, json_serializable; `dartfmt -n --set-exit-if-changed .`, `dartanalyzer --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable;commands:dartfmt-dartanalyzer"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_annotation-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: beta
sdk: "2.12.0"
- id: checkout
uses: actions/checkout@v2
- id: _test_yaml_pub_upgrade
Expand Down Expand Up @@ -134,7 +134,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -205,22 +205,22 @@ jobs:
working-directory: json_serializable
run: dartanalyzer --fatal-infos .
job_004:
name: "unit_test; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`"
name: "unit_test; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: beta
sdk: "2.12.0"
- id: checkout
uses: actions/checkout@v2
- id: _test_yaml_pub_upgrade
Expand Down Expand Up @@ -277,7 +277,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -323,22 +323,22 @@ jobs:
- job_002
- job_003
job_006:
name: "unit_test; Dart beta; PKG: json_serializable; `pub run test -p chrome`"
name: "unit_test; Dart 2.12.0; PKG: json_serializable; `pub run test -p chrome`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable;commands:test_2"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable;commands:test_2"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: beta
sdk: "2.12.0"
- id: checkout
uses: actions/checkout@v2
- id: json_serializable_pub_upgrade
Expand Down Expand Up @@ -368,7 +368,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand All @@ -387,22 +387,22 @@ jobs:
- job_002
- job_003
job_008:
name: "ensure_build; Dart beta; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
name: "ensure_build; Dart 2.12.0; PKGS: _test_yaml, checked_yaml, example, json_serializable; `pub run test --run-skipped -t presubmit-only test/ensure_build_test.dart`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable;commands:test_1"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:beta;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:beta
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:_test_yaml-checked_yaml-example-json_serializable
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: beta
sdk: "2.12.0"
- id: checkout
uses: actions/checkout@v2
- id: _test_yaml_pub_upgrade
Expand Down Expand Up @@ -463,7 +463,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down
2 changes: 1 addition & 1 deletion _test_yaml/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
dart:
- beta # change this to 1.12.0 when it's released!
- 2.12.0
- dev

stages:
Expand Down
2 changes: 1 addition & 1 deletion _test_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: _test_yaml
publish_to: none

environment:
sdk: '>=2.12.0-0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
build_runner: ^1.0.0
Expand Down
3 changes: 0 additions & 3 deletions _test_yaml/test/yaml_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ line 4, column 21 of file.yaml: Unsupported value for "configLocation". Illegal
╵'''
};

// ignore: deprecated_member_use
final throwsCastError = throwsA(isA<CastError>());

T roundTripObject<T>(
T object,
T Function(Map<String, dynamic> json) factory, {
Expand Down
6 changes: 6 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ linter:
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_catching_errors
- avoid_dynamic_calls
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
Expand All @@ -20,6 +21,7 @@ linter:
- avoid_returning_null
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
- avoid_types_as_parameter_names
- avoid_unused_constructor_parameters
- avoid_void_async
Expand Down Expand Up @@ -87,6 +89,7 @@ linter:
- provide_deprecation_message
- recursive_getters
- slash_for_doc_comments
- sort_child_properties_last
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
Expand All @@ -105,7 +108,10 @@ linter:
- unnecessary_string_interpolations
- unnecessary_this
- unrelated_type_equality_checks
- unsafe_html
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_is_even_rather_than_modulo
- use_rethrow_when_possible
- use_string_buffers
- valid_regexps
Expand Down
9 changes: 8 additions & 1 deletion checked_yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 2.0.0-dev
## 2.0.1

- If `CheckedFromJsonException` is caught for a key missing in the source map,
include those details in the thrown `ParsedYamlException`.

- Correctly handle the case where `CheckedFromJsonException.message` is `null`.

## 2.0.0

- *BREAKING* `checkedYamlDecode` `sourceUrl` parameter is now a `Uri`.
- Require at least Dart `2.12.0-0`.
Expand Down
1 change: 0 additions & 1 deletion checked_yaml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ for the class annotation.
class Configuration {
@JsonKey(required: true)
final String name;
@JsonKey(required: true)
final int count;
Configuration({required this.name, required this.count}) {
Expand Down
1 change: 0 additions & 1 deletion checked_yaml/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ part 'example.g.dart';
class Configuration {
@JsonKey(required: true)
final String name;
@JsonKey(required: true)
final int count;

Configuration({required this.name, required this.count}) {
Expand Down
3 changes: 1 addition & 2 deletions checked_yaml/example/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions checked_yaml/lib/checked_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ ParsedYamlException toParsedYamlException(
innerError: exception,
);
} else {
final yamlValue = yamlMap.nodes[exception.key];

if (yamlValue == null) {
// TODO: test this case!
if (exception.key == null) {
return ParsedYamlException(
exception.message ?? 'There was an error parsing the map.',
yamlMap,
innerError: exception,
);
} else if (!yamlMap.containsKey(exception.key)) {
return ParsedYamlException(
exception.message!,
[
'Missing key "${exception.key}".',
if (exception.message != null) exception.message!,
].join(' '),
yamlMap,
innerError: exception,
);
Expand All @@ -91,7 +97,7 @@ ParsedYamlException toParsedYamlException(
}
return ParsedYamlException(
message,
yamlValue,
yamlMap.nodes[exception.key] ?? yamlMap,
innerError: exception,
);
}
Expand Down
2 changes: 1 addition & 1 deletion checked_yaml/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://github.com/google/mono_repo.dart for details on this file
dart:
- beta # change this to 1.12.0 when it's released!
- 2.12.0
- dev

stages:
Expand Down
19 changes: 9 additions & 10 deletions checked_yaml/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
name: checked_yaml
version: 1.9.0-dev
version: 2.0.1

description: >-
Generate more helpful exceptions when decoding YAML documents using
package:json_serializable and package:yaml.
repository: https://github.com/google/json_serializable.dart
repository: https://github.com/google/json_serializable.dart/tree/master/checked_yaml
environment:
sdk: '>=2.12.0-0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
json_annotation: '>=2.2.0 <5.0.0'
json_annotation: ^4.0.0
source_span: ^1.8.0
yaml: ^3.0.0

dev_dependencies:
build_runner: ^1.0.0
build_verify: ^1.1.0
json_serializable: ^3.0.0
json_serializable: ^4.0.0
path: ^1.0.0
test: ^1.16.0
test_process: ^1.0.1
test_process: ^2.0.0

dependency_overrides:
json_annotation:
path: ../json_annotation
json_serializable:
path: ../json_serializable
# Need to update dependencies on these packages
build_config: ^0.4.4
pubspec_parse: ^0.1.5
42 changes: 42 additions & 0 deletions checked_yaml/test/custom_error_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:checked_yaml/checked_yaml.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

void main() {
test('bob', () {
expect(
() => checkedYamlDecode(
'{"innerMap": {}}',
(m) {
throw CheckedFromJsonException(
m!['innerMap'] as YamlMap,
null,
'nothing',
null,
);
},
),
throwsA(
isA<ParsedYamlException>()
.having(
(e) => e.message,
'message',
'There was an error parsing the map.',
)
.having((e) => e.yamlNode, 'yamlNode', isA<YamlMap>())
.having(
(e) => e.innerError,
'innerError',
isA<CheckedFromJsonException>(),
)
.having((e) => e.formattedMessage, 'formattedMessage', '''
line 1, column 14: There was an error parsing the map.
1 │ {"innerMap": {}}
│ ^^
╵'''),
),
);
});
}

0 comments on commit 3c6d717

Please sign in to comment.