[ios]Add errors reporting (#15391)

* add errors reporting

* [ios] report error if rendering takes > 1 second. (#15633)
This commit is contained in:
m-stephen
2019-09-20 10:14:44 +08:00
committed by GitHub
parent da6a7e9318
commit 8128d709b6
7 changed files with 83 additions and 7 deletions

View File

@@ -252,12 +252,15 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
NSString *description = @(mbgl::util::toString(mbglError).c_str());
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description};
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeSnapshotFailed userInfo:userInfo];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
// Dispatch to result queue
dispatch_async(queue, ^{
strongSelf.completion(nil, error);
strongSelf.completion = nil;
});
} else {
#if TARGET_OS_IPHONE
MGLImage *mglImage = [[MGLImage alloc] initWithMGLPremultipliedImage:std::move(image) scale:strongSelf.options.scale];
@@ -636,6 +639,9 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
NSError *error = [NSError errorWithDomain:MGLErrorDomain
code:errorCode
userInfo:userInfo];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
completion(NULL, error);
});
}

View File

@@ -345,6 +345,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
NSLocalizedDescriptionKey: description,
NSLocalizedFailureReasonErrorKey: @(mbgl::util::toString(result.error()).c_str())
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
} else {
auto& regions = result.value();
packs = [NSMutableArray arrayWithCapacity:regions.size()];
@@ -404,6 +407,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:errorDescription ? @{
NSLocalizedDescriptionKey: errorDescription,
} : nil];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
if (completion) {
MGLOfflinePack *pack = mbglOfflineRegion ? [[MGLOfflinePack alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(mbglOfflineRegion.value()))] : nil;
@@ -441,6 +447,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
if (completion) {
dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
@@ -464,6 +473,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
});
if (completion) {
@@ -491,6 +503,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(result.error()).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
} else {
auto& regions = result.value();
packs = [NSMutableArray arrayWithCapacity:regions.size()];
@@ -522,6 +537,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
dispatch_sync(dispatch_get_main_queue(), ^ {
completion(error);
@@ -539,6 +557,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
dispatch_async(dispatch_get_main_queue(), ^ {
completion(error);
@@ -555,6 +576,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeModifyingOfflineStorageFailed userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
dispatch_async(dispatch_get_main_queue(), [&, completion, error](void) {
completion(error);
@@ -571,6 +595,9 @@ const MGLExceptionName MGLUnsupportedRegionTypeException = @"MGLUnsupportedRegio
error = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
}
dispatch_async(dispatch_get_main_queue(), ^{
completion(error);

View File

@@ -5,6 +5,10 @@
#import "NSString+MGLAdditions.h"
#import "MGLTypes.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEEventsManager.h"
#endif
#import <mbgl/util/geo.hpp>
bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D rhs) {
@@ -18,6 +22,9 @@ bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D r
if (!string) {
if (outError) {
*outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:nil];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:*outError];
#endif
}
return nil;
}
@@ -30,6 +37,9 @@ bool operator==(const CLLocationCoordinate2D lhs, const CLLocationCoordinate2D r
*outError = [NSError errorWithDomain:MGLErrorDomain code:MGLErrorCodeUnknown userInfo:@{
NSLocalizedFailureReasonErrorKey: @(err.what()),
}];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:*outError];
#endif
}
return nil;
}

View File

@@ -3,6 +3,10 @@
#import "MGLMapView_Private.h"
#import "NSBundle+MGLAdditions.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEEventsManager.h"
#endif
#include <mbgl/style/style.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/style/source.hpp>
@@ -86,6 +90,10 @@ const MGLExceptionName MGLInvalidStyleSourceException = @"MGLInvalidStyleSourceE
*outError = [NSError errorWithDomain:MGLErrorDomain
code:MGLErrorCodeSourceIsInUseCannotRemove
userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:*outError];
#endif
}
} else if (outError) {
// TODO: Consider raising an exception here
@@ -96,6 +104,9 @@ const MGLExceptionName MGLInvalidStyleSourceException = @"MGLInvalidStyleSourceE
*outError = [NSError errorWithDomain:MGLErrorDomain
code:MGLErrorCodeSourceIdentifierMismatch
userInfo:@{ NSLocalizedDescriptionKey : localizedDescription }];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:*outError];
#endif
}
return removed;

View File

@@ -57,7 +57,9 @@ typedef NS_ENUM(NSInteger, MGLErrorCode) {
/** An error occurred while modifying the offline storage database */
MGLErrorCodeModifyingOfflineStorageFailed = 9,
/** Source is invalid and cannot be removed from the style (e.g. after a style change) */
MGLErrorCodeSourceCannotBeRemovedFromStyle = 10
MGLErrorCodeSourceCannotBeRemovedFromStyle = 10,
/** An error occurred while rendering */
MGLErrorCodeRenderingError = 11,
};
/** Options for enabling debugging features in an `MGLMapView` instance. */

View File

@@ -3,6 +3,10 @@
#import "MGLStyle_Private.h"
#import "NSBundle+MGLAdditions.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEEventsManager.h"
#endif
std::unique_ptr<MGLMapViewImpl> MGLMapViewImpl::Create(MGLMapView* nativeView) {
return std::make_unique<MGLMapViewOpenGLImpl>(nativeView);
}
@@ -61,6 +65,9 @@ void MGLMapViewImpl::onDidFailLoadingMap(mbgl::MapLoadError mapError, const std:
NSLocalizedFailureReasonErrorKey: @(what.c_str()),
};
NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo];
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
[[MMEEventsManager sharedManager] reportError:error];
#endif
[mapView mapViewDidFailLoadingMapWithError:error];
}

View File

@@ -2,6 +2,11 @@
#import "MGLLoggingConfiguration_Private.h"
#import "MGLMapView+OpenGL.h"
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MMEConstants.h"
#import "MGLMapboxEvents.h"
#endif
#include <mbgl/gl/renderable_resource.hpp>
#import <GLKit/GLKit.h>
@@ -96,7 +101,7 @@ void MGLMapViewOpenGLImpl::setPresentsWithTransaction(const bool value) {
void MGLMapViewOpenGLImpl::display() {
auto& resource = getResource<MGLMapViewOpenGLRenderableResource>();
#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY
// See https://github.com/mapbox/mapbox-gl-native/issues/14232
// glClear can be blocked for 1 second. This code is an "escape hatch",
// an attempt to detect this situation and rebuild the GL views.
@@ -106,14 +111,22 @@ void MGLMapViewOpenGLImpl::display() {
CFTimeInterval after = CACurrentMediaTime();
if (after - before >= 1.0) {
#ifdef MGL_RECREATE_GL_IN_AN_EMERGENCY
dispatch_async(dispatch_get_main_queue(), ^{
emergencyRecreateGL();
});
}
}
else
#else
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSError *error = [NSError errorWithDomain:MGLErrorDomain
code:MGLErrorCodeRenderingError
userInfo:@{ NSLocalizedFailureReasonErrorKey :
@"https://github.com/mapbox/mapbox-gl-native/issues/14232" }];
[[MMEEventsManager sharedManager] reportError:error];
});
#endif
{
}
} else {
[resource.glView display];
}
}