Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Automated g4 rollback of changelist 184594151.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Teams are relying on this throwsArgumentError, so I'll have to do this behind a flag...

*** Original change description ***

feat(Core): Start work on a MissingProviderError, with better error messages.

Added a simple test (passes), and a complex test (skipped, does not pass). In
dev-mode we will start tracking the chain of failed lookups and give a better
error message, i.e. "No provider found for B: A -> B".

Work towards #434.

***

PiperOrigin-RevId: 184617305
  • Loading branch information
matanlurey committed Feb 6, 2018
1 parent a058f6c commit 76e8924
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 142 deletions.
13 changes: 0 additions & 13 deletions _tests/lib/matchers.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import 'dart:html';

import 'package:angular/src/di/errors.dart';
import 'package:angular/src/facade/lang.dart';
import 'package:test/test.dart';

/// Matches a missing provider error thrown at runtime.
final Matcher throwsMissingProviderError = (() {
if (assertionsEnabled()) {
return _throwsMissingProviderError;
}
return throwsArgumentError;
})();

final _isMissingProviderError = const isInstanceOf<MissingProviderError>();
final _throwsMissingProviderError = throwsA(_isMissingProviderError);

/// Matches textual content of an element including children.
Matcher hasTextContent(expected) => new _HasTextContent(expected);

Expand Down
46 changes: 9 additions & 37 deletions _tests/test/di/injector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:angular/src/di/injector/injector.dart';
import 'package:test/test.dart';
import 'package:angular/src/di/reflector.dart' as reflector;
import 'package:angular_test/angular_test.dart';
import 'package:_tests/matchers.dart';

import 'injector_test.template.dart' as ng;

Expand Down Expand Up @@ -44,26 +43,11 @@ void main() {

test('should throw by default', () {
i = new Injector.empty();
expect(
() => i.get(ExampleService),
throwsMissingProviderError,
);
expect(
() => i.inject(ExampleService),
throwsMissingProviderError,
);
expect(
() => i.injectFromSelf(ExampleService),
throwsMissingProviderError,
);
expect(
() => i.injectFromAncestry(ExampleService),
throwsMissingProviderError,
);
expect(
() => i.injectFromParent(ExampleService),
throwsMissingProviderError,
);
expect(() => i.get(ExampleService), throwsArgumentError);
expect(() => i.inject(ExampleService), throwsArgumentError);
expect(() => i.injectFromSelf(ExampleService), throwsArgumentError);
expect(() => i.injectFromAncestry(ExampleService), throwsArgumentError);
expect(() => i.injectFromParent(ExampleService), throwsArgumentError);
});

test('should use orElse if provided', () {
Expand All @@ -80,10 +64,7 @@ void main() {
i = new Injector.empty(parent);
expect(i.get(ExampleService), 123);
expect(i.inject(ExampleService), 123);
expect(
() => i.injectFromSelf(ExampleService),
throwsMissingProviderError,
);
expect(() => i.injectFromSelf(ExampleService), throwsArgumentError);
expect(i.injectFromAncestry(ExampleService), 123);
expect(i.injectFromParent(ExampleService), 123);
});
Expand All @@ -102,14 +83,8 @@ void main() {
expect(i.get(ExampleService), 123);
expect(i.inject(ExampleService), 123);
expect(i.injectFromSelf(ExampleService), 123);
expect(
() => i.injectFromAncestry(ExampleService),
throwsMissingProviderError,
);
expect(
() => i.injectFromParent(ExampleService),
throwsMissingProviderError,
);
expect(() => i.injectFromAncestry(ExampleService), throwsArgumentError);
expect(() => i.injectFromParent(ExampleService), throwsArgumentError);
});

test('should return itself if Injector is passed', () {
Expand Down Expand Up @@ -218,10 +193,7 @@ void main() {

test('should thrown when a provider was not found', () {
i = new Injector.slowReflective([]);
expect(
() => i.get(#ABC),
throwsMissingProviderError,
);
expect(() => i.get(#ABC), throwsArgumentError);
});

test('should support resolveAndCreateChild', () {
Expand Down
36 changes: 0 additions & 36 deletions _tests/test/di/missing_provider_test.dart

This file was deleted.

9 changes: 4 additions & 5 deletions _tests/test/regression/755_reflective_meta_fail_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@TestOn('browser')

import 'package:test/test.dart';
import 'package:_tests/matchers.dart';
import 'package:angular/angular.dart';

import '755_reflective_meta_fail_test.template.dart' as ng_generated;
Expand All @@ -16,10 +15,10 @@ void main() {
const Provider(ServiceInjectingToken, useClass: ServiceInjectingToken),
// Intentionally omit a binding for "stringToken".
]);
expect(
() => injector.get(ServiceInjectingToken),
throwsMissingProviderError,
);

// Used to return an Object representing the secret "notFound" instead of
// throwing ArgumentError, which was the expected behavior.
expect(() => injector.get(ServiceInjectingToken), throwsArgumentError);
});
}

Expand Down
46 changes: 0 additions & 46 deletions angular/lib/src/di/errors.dart

This file was deleted.

6 changes: 1 addition & 5 deletions angular/lib/src/di/injector/injector.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:meta/meta.dart';

import '../errors.dart';

import 'empty.dart';
import 'hierarchical.dart';
import 'map.dart';
Expand All @@ -19,10 +17,8 @@ typedef T OrElseInject<T>(Injector injector, Object token);
/// **INTERNAL ONLY**: Sentinel value for determining a missing DI instance.
const Object throwIfNotFound = const Object();

/// **INTERNAL ONLY**: Throws an error that [token] was not found.
@alwaysThrows
Null throwsNotFound(Injector injector, Object token) {
throw MissingProviderError.create(injector, token);
throw new ArgumentError('No provider found for $token.');
}

/// Support for imperatively loading dependency injected services at runtime.
Expand Down

0 comments on commit 76e8924

Please sign in to comment.