fix app crash and log weird error to help track down issue with license changing

This commit is contained in:
Sean Yesmunt 2019-12-19 01:33:06 -05:00
parent 8331e0ecf9
commit 5fc6dd9b3d
5 changed files with 33 additions and 17 deletions

View file

@ -21,6 +21,7 @@ ElectronCookies.enable({
// @endif
type Analytics = {
error: string => void,
pageView: string => void,
setUser: Object => void,
toggle: (boolean, ?boolean) => void,
@ -44,6 +45,11 @@ type LogPublishParams = {
let analyticsEnabled: boolean = true;
const analytics: Analytics = {
error: message => {
if (analyticsEnabled) {
Lbryio.call('event', 'desktop_error', { error_message: message });
}
},
pageView: path => {
if (analyticsEnabled) {
ReactGA.pageview(path, [SECOND_TRACKER_NAME]);

View file

@ -1,12 +1,12 @@
// @flow
import type { Node } from 'react';
import { Lbryio } from 'lbryinc';
import React, { Fragment } from 'react';
import Yrbl from 'component/yrbl';
import Button from 'component/button';
import { withRouter } from 'react-router';
import Native from 'native';
import { Lbry } from 'lbry-redux';
import analytics from 'analytics';
type Props = {
children: Node,
@ -38,7 +38,8 @@ class ErrorBoundary extends React.Component<Props, State> {
errorMessage += 'lbry.tv\n';
errorMessage += `page: ${window.location.pathname + window.location.search}\n`;
errorMessage += error.stack;
this.log(errorMessage);
analytics.error(errorMessage);
// @endif
// @if TARGET='app'
Native.getAppVersionInfo().then(({ localVersion }) => {
@ -47,19 +48,12 @@ class ErrorBoundary extends React.Component<Props, State> {
errorMessage += `sdk version: ${sdkVersion}\n`;
errorMessage += `page: ${window.location.href.split('.html')[1]}\n`;
errorMessage += `${error.stack}`;
this.log(errorMessage);
analytics.error(errorMessage);
});
});
// @endif
}
log(message) {
declare var app: { env: string };
if (app.env === 'production') {
Lbryio.call('event', 'desktop_error', { error_message: message });
}
}
refresh() {
const { history } = this.props;
// use history.replace instead of history.push so the user can't click back to the errored page

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { selectPublishFormValues, doUpdatePublishForm } from 'lbry-redux';
import { selectPublishFormValues, doUpdatePublishForm, doToast } from 'lbry-redux';
import PublishPage from './view';
const select = state => ({
@ -8,6 +8,7 @@ const select = state => ({
const perform = dispatch => ({
updatePublishForm: value => dispatch(doUpdatePublishForm(value)),
showToast: message => dispatch(doToast({ isError: true, message })),
});
export default connect(

View file

@ -2,6 +2,7 @@
import * as React from 'react';
import { FormField } from 'component/common/form';
import { CC_LICENSES, LEGACY_CC_LICENSES, COPYRIGHT, OTHER, PUBLIC_DOMAIN, NONE } from 'constants/licenses';
import analytics from 'analytics';
type Props = {
licenseType: ?string,
@ -10,6 +11,7 @@ type Props = {
handleLicenseChange: (string, string) => void,
handleLicenseDescriptionChange: (SyntheticInputEvent<*>) => void,
handleLicenseUrlChange: (SyntheticInputEvent<*>) => void,
showToast: string => void,
};
class LicenseType extends React.PureComponent<Props> {
@ -20,15 +22,26 @@ class LicenseType extends React.PureComponent<Props> {
}
handleLicenseOnChange(event: SyntheticInputEvent<*>) {
const { handleLicenseChange } = this.props;
const { handleLicenseChange, showToast } = this.props;
// $FlowFixMe
const { options, selectedIndex } = event.target;
const selectedOption = options[selectedIndex];
const licenseType = selectedOption.value;
const licenseUrl = selectedOption.getAttribute('data-url');
if (options !== null) {
const selectedOption = options[selectedIndex];
const licenseType = selectedOption.value;
const licenseUrl = selectedOption.getAttribute('data-url');
handleLicenseChange(licenseType, licenseUrl);
handleLicenseChange(licenseType, licenseUrl);
} else {
// There were users where this options were null for some reason
// This will at least make it so the app doesn't crash
// Hopefully this helps figure it out
analytics.error('Error changing the publish license\n' + JSON.stringify(this.props));
showToast(
__('There was an error updating the license type. If it continues to happen send an email to help@lbry.com.')
);
}
}
render() {

View file

@ -15,10 +15,11 @@ type Props = {
licenseUrl: ?string,
disabled: boolean,
updatePublishForm: ({}) => void,
showToast: string => void,
};
function PublishAdvanced(props: Props) {
const { language, name, licenseType, otherLicenseDescription, licenseUrl, updatePublishForm } = props;
const { language, name, licenseType, otherLicenseDescription, licenseUrl, updatePublishForm, showToast } = props;
const [hideSection, setHideSection] = usePersistedState('publish-advanced-options', true);
function toggleHideSection() {
@ -66,6 +67,7 @@ function PublishAdvanced(props: Props) {
</FormField>
<LicenseType
showToast={showToast}
licenseType={licenseType}
otherLicenseDescription={otherLicenseDescription}
licenseUrl={licenseUrl}