Extra debug logging
This commit is contained in:
parent
cdff8db311
commit
814eb5faec
|
@ -145,19 +145,19 @@ export class BBCodeParser {
|
||||||
tagStart = i;
|
tagStart = i;
|
||||||
paramStart = -1;
|
paramStart = -1;
|
||||||
} else {
|
} else {
|
||||||
console.log('Hit depth tagOpen', depth);
|
// console.log('Hit depth tagOpen', depth);
|
||||||
}
|
}
|
||||||
} else if(c === '=' && paramStart === -1) {
|
} else if(c === '=' && paramStart === -1) {
|
||||||
if (depth <= 1) {
|
if (depth <= 1) {
|
||||||
paramStart = i;
|
paramStart = i;
|
||||||
} else {
|
} else {
|
||||||
console.log('Hit depth paramStart', depth);
|
// console.log('Hit depth paramStart', depth);
|
||||||
}
|
}
|
||||||
} else if(c === ']') {
|
} else if(c === ']') {
|
||||||
depth--;
|
depth--;
|
||||||
|
|
||||||
if (depth !== 0) {
|
if (depth !== 0) {
|
||||||
console.log('Hit depth tagClose', depth);
|
// console.log('Hit depth tagClose', depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depth === 0) {
|
if (depth === 0) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import {InlineDisplayMode} from '../interfaces';
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import log from 'electron-log'; //tslint:disable-line:match-default-export-name
|
||||||
import {Component, Hook, Prop} from '@f-list/vue-ts';
|
import {Component, Hook, Prop} from '@f-list/vue-ts';
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Modal from '../components/Modal.vue';
|
import Modal from '../components/Modal.vue';
|
||||||
|
@ -123,6 +124,17 @@ import {InlineDisplayMode} from '../interfaces';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
core.connection.onEvent('closed', (isReconnect) => {
|
core.connection.onEvent('closed', (isReconnect) => {
|
||||||
|
if(process.env.NODE_ENV !== 'production') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'connection.closed',
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
error: this.error,
|
||||||
|
isReconnect
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if(isReconnect) (<Modal>this.$refs['reconnecting']).show(true);
|
if(isReconnect) (<Modal>this.$refs['reconnecting']).show(true);
|
||||||
if(this.connected) core.notifications.playSound('logout');
|
if(this.connected) core.notifications.playSound('logout');
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
@ -152,6 +164,17 @@ import {InlineDisplayMode} from '../interfaces';
|
||||||
document.title = (hasNew ? '💬 ' : '') + l(core.connection.isOpen ? 'title.connected' : 'title', core.connection.character);
|
document.title = (hasNew ? '💬 ' : '') + l(core.connection.isOpen ? 'title.connected' : 'title', core.connection.character);
|
||||||
});
|
});
|
||||||
core.connection.onError((e) => {
|
core.connection.onError((e) => {
|
||||||
|
|
||||||
|
if(process.env.NODE_ENV !== 'production') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'connection.error',
|
||||||
|
error: errorToString(e),
|
||||||
|
character: core.characters.ownCharacter?.name
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if((<Error & {request?: object}>e).request !== undefined) {//catch axios network errors
|
if((<Error & {request?: object}>e).request !== undefined) {//catch axios network errors
|
||||||
this.error = l('login.connectError', errorToString(e));
|
this.error = l('login.connectError', errorToString(e));
|
||||||
this.connecting = false;
|
this.connecting = false;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import throat from 'throat';
|
import throat from 'throat';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
|
import log from 'electron-log'; //tslint:disable-line:match-default-export-name
|
||||||
|
|
||||||
import core from '../core';
|
import core from '../core';
|
||||||
import { Conversation } from '../interfaces';
|
import { Conversation } from '../interfaces';
|
||||||
import Timer = NodeJS.Timer;
|
import Timer = NodeJS.Timer;
|
||||||
|
@ -53,14 +55,34 @@ export class AdManager {
|
||||||
|
|
||||||
// This makes sure there is a 5s delay between channel posts
|
// This makes sure there is a 5s delay between channel posts
|
||||||
private async sendAdToChannel(msg: string, conv: Conversation.ChannelConversation): Promise<void> {
|
private async sendAdToChannel(msg: string, conv: Conversation.ChannelConversation): Promise<void> {
|
||||||
|
const initTime = Date.now();
|
||||||
|
|
||||||
await adManagerThroat(
|
await adManagerThroat(
|
||||||
async() => {
|
async() => {
|
||||||
|
const throatTime = Date.now();
|
||||||
|
|
||||||
const delta = Date.now() - core.cache.getLastPost().getTime();
|
const delta = Date.now() - core.cache.getLastPost().getTime();
|
||||||
|
|
||||||
if ((delta > 0) && (delta < AdManager.POST_MANUAL_THRESHOLD)) {
|
if ((delta > 0) && (delta < AdManager.POST_MANUAL_THRESHOLD)) {
|
||||||
await this.delay(delta);
|
await this.delay(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const delayTime = Date.now();
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'sendAdToChannel',
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
channel: conv.channel.name,
|
||||||
|
throatDelta: throatTime - initTime,
|
||||||
|
delayDelta: delayTime - throatTime,
|
||||||
|
totalWait: delayTime - initTime,
|
||||||
|
msg
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await conv.sendAd(msg);
|
await conv.sendAd(msg);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import MessageType = Interfaces.Message.Type;
|
||||||
import {EventBus} from './preview/event-bus';
|
import {EventBus} from './preview/event-bus';
|
||||||
import throat from 'throat';
|
import throat from 'throat';
|
||||||
import Bluebird from 'bluebird';
|
import Bluebird from 'bluebird';
|
||||||
|
import log from 'electron-log'; //tslint:disable-line:match-default-export-name
|
||||||
|
|
||||||
function createMessage(this: any, type: MessageType, sender: Character, text: string, time?: Date): Message {
|
function createMessage(this: any, type: MessageType, sender: Character, text: string, time?: Date): Message {
|
||||||
if(type === MessageType.Message && isAction(text)) {
|
if(type === MessageType.Message && isAction(text)) {
|
||||||
|
@ -395,13 +396,33 @@ class ChannelConversation extends Conversation implements Interfaces.ChannelConv
|
||||||
if (text.length < 1)
|
if (text.length < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const initTime = Date.now();
|
||||||
|
|
||||||
await Conversation.conversationThroat(
|
await Conversation.conversationThroat(
|
||||||
async() => {
|
async() => {
|
||||||
|
const throatTime = Date.now();
|
||||||
|
|
||||||
await Conversation.testPostDelay();
|
await Conversation.testPostDelay();
|
||||||
|
|
||||||
|
const delayTime = Date.now();
|
||||||
|
|
||||||
core.connection.send('LRP', {channel: this.channel.id, message: text});
|
core.connection.send('LRP', {channel: this.channel.id, message: text});
|
||||||
core.cache.markLastPostTime();
|
core.cache.markLastPostTime();
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'sendAd',
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
channel: this.channel.name,
|
||||||
|
throatDelta: throatTime - initTime,
|
||||||
|
delayDelta: delayTime - throatTime,
|
||||||
|
totalWait: delayTime - initTime,
|
||||||
|
text
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await this.addMessage(
|
await this.addMessage(
|
||||||
createMessage(MessageType.Ad, core.characters.ownCharacter, text, new Date())
|
createMessage(MessageType.Ad, core.characters.ownCharacter, text, new Date())
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,11 +2,15 @@ import Axios, {AxiosError, AxiosResponse} from 'axios';
|
||||||
import * as qs from 'qs';
|
import * as qs from 'qs';
|
||||||
import {Connection as Interfaces, WebSocketConnection} from './interfaces';
|
import {Connection as Interfaces, WebSocketConnection} from './interfaces';
|
||||||
import ReadyState = WebSocketConnection.ReadyState;
|
import ReadyState = WebSocketConnection.ReadyState;
|
||||||
|
import log from 'electron-log'; //tslint:disable-line:match-default-export-name
|
||||||
|
import core from '../chat/core';
|
||||||
|
|
||||||
const fatalErrors = [2, 3, 4, 9, 30, 31, 33, 39, 40, 62, -4];
|
const fatalErrors = [2, 3, 4, 9, 30, 31, 33, 39, 40, 62, -4];
|
||||||
const dieErrors = [9, 30, 31, 39, 40];
|
const dieErrors = [9, 30, 31, 39, 40];
|
||||||
|
|
||||||
let lastFetch = Date.now();
|
let lastFetch = Date.now();
|
||||||
|
let lastApiTicketFetch = Date.now();
|
||||||
|
|
||||||
|
|
||||||
async function queryApi(this: void, endpoint: string, data: object): Promise<AxiosResponse> {
|
async function queryApi(this: void, endpoint: string, data: object): Promise<AxiosResponse> {
|
||||||
if (false) {
|
if (false) {
|
||||||
|
@ -117,15 +121,41 @@ export default class Connection implements Interfaces.Connection {
|
||||||
|
|
||||||
async queryApi<T = object>(endpoint: string, data?: {account?: string, ticket?: string}): Promise<T> {
|
async queryApi<T = object>(endpoint: string, data?: {account?: string, ticket?: string}): Promise<T> {
|
||||||
if(!this.ticketProvider) throw new Error('No credentials set!');
|
if(!this.ticketProvider) throw new Error('No credentials set!');
|
||||||
|
|
||||||
if(data === undefined) data = {};
|
if(data === undefined) data = {};
|
||||||
|
|
||||||
data.account = this.account;
|
data.account = this.account;
|
||||||
data.ticket = this.ticket;
|
data.ticket = this.ticket;
|
||||||
|
|
||||||
let res = <T & {error: string}>(await queryApi(endpoint, data)).data;
|
let res = <T & {error: string}>(await queryApi(endpoint, data)).data;
|
||||||
|
|
||||||
if(res.error === 'Invalid ticket.' || res.error === 'Your login ticket has expired (five minutes) or no ticket requested.') {
|
if(res.error === 'Invalid ticket.' || res.error === 'Your login ticket has expired (five minutes) or no ticket requested.') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'api.ticket.loss',
|
||||||
|
error: res.error,
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
deltaToLastApiCall: Date.now() - lastFetch,
|
||||||
|
deltaToLastApiTicket: Date.now() - lastApiTicketFetch
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
data.ticket = this.ticket = await this.ticketProvider();
|
data.ticket = this.ticket = await this.ticketProvider();
|
||||||
res = <T & {error: string}>(await queryApi(endpoint, data)).data;
|
res = <T & {error: string}>(await queryApi(endpoint, data)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res.error !== '') {
|
if(res.error !== '') {
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'error.api.query',
|
||||||
|
error: res.error,
|
||||||
|
endpoint,
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
deltaToLastApiCall: Date.now() - lastFetch,
|
||||||
|
deltaToLastApiTicket: Date.now() - lastApiTicketFetch
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const error = new Error(res.error);
|
const error = new Error(res.error);
|
||||||
(<Error & {request: true}>error).request = true;
|
(<Error & {request: true}>error).request = true;
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -203,14 +233,42 @@ export default class Connection implements Interfaces.Connection {
|
||||||
private async getTicket(password: string): Promise<string> {
|
private async getTicket(password: string): Promise<string> {
|
||||||
console.log('Acquiring new API ticket');
|
console.log('Acquiring new API ticket');
|
||||||
|
|
||||||
if (false) {
|
if(process.env.NODE_ENV !== 'production') {
|
||||||
console.log(`https://www.f-list.net/json/getApiTicket.php, gap: ${Date.now() - lastFetch}ms`);
|
console.log(`https://www.f-list.net/json/getApiTicket.php, gap: ${Date.now() - lastApiTicketFetch}ms`);
|
||||||
lastFetch = Date.now();
|
|
||||||
|
log.debug(
|
||||||
|
{
|
||||||
|
type: 'api.getTicket',
|
||||||
|
character: core.characters.ownCharacter?.name,
|
||||||
|
deltaToLastApiCall: Date.now() - lastFetch,
|
||||||
|
deltaToLastApiTicket: Date.now() - lastApiTicketFetch
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
lastApiTicketFetch = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = <{ticket?: string, error: string}>(await Axios.post('https://www.f-list.net/json/getApiTicket.php', qs.stringify(
|
const data = <{ticket?: string, error: string}>(await Axios.post('https://www.f-list.net/json/getApiTicket.php', qs.stringify(
|
||||||
{account: this.account, password, no_friends: true, no_bookmarks: true, no_characters: true}))).data;
|
{account: this.account, password, no_friends: true, no_bookmarks: true, no_characters: true}))).data;
|
||||||
|
|
||||||
if(data.ticket !== undefined) return data.ticket;
|
if(data.ticket !== undefined) return data.ticket;
|
||||||
|
|
||||||
|
if(process.env.NODE_ENV !== 'production') {
|
||||||
|
console.error('API Ticket Error', data.error);
|
||||||
|
|
||||||
|
log.error(
|
||||||
|
{
|
||||||
|
type: 'error.api.getTicket',
|
||||||
|
character: core.characters.ownCharacter.name,
|
||||||
|
error: data.error,
|
||||||
|
deltaToLastApiCall: Date.now() - lastFetch,
|
||||||
|
deltaToLastApiTicket: Date.now() - lastApiTicketFetch
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
lastApiTicketFetch = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
throw new Error(data.error);
|
throw new Error(data.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue