2021-07-01 14:31:20 -07:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-20 18:41:51 -07:00
|
|
|
import type * as channels from '@protocol/channels';
|
|
|
|
|
import type { ActionTraceEvent } from '@trace/trace';
|
2021-07-01 14:31:20 -07:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import './consoleTab.css';
|
2021-07-01 20:46:56 -07:00
|
|
|
import * as modelUtil from './modelUtil';
|
2021-07-01 14:31:20 -07:00
|
|
|
|
|
|
|
|
export const ConsoleTab: React.FunctionComponent<{
|
|
|
|
|
action: ActionTraceEvent | undefined,
|
2021-07-01 20:46:56 -07:00
|
|
|
}> = ({ action }) => {
|
2021-07-01 14:31:20 -07:00
|
|
|
const entries = React.useMemo(() => {
|
|
|
|
|
if (!action)
|
|
|
|
|
return [];
|
|
|
|
|
const entries: { message?: channels.ConsoleMessageInitializer, error?: channels.SerializedError }[] = [];
|
2021-10-15 14:22:49 -08:00
|
|
|
const context = modelUtil.context(action);
|
2021-07-01 20:46:56 -07:00
|
|
|
for (const event of modelUtil.eventsForAction(action)) {
|
2023-02-27 15:29:20 -08:00
|
|
|
if (event.method !== 'console' && event.method !== 'pageError')
|
2021-07-01 20:46:56 -07:00
|
|
|
continue;
|
2023-02-27 15:29:20 -08:00
|
|
|
if (event.method === 'console') {
|
|
|
|
|
const { guid } = event.params.message;
|
|
|
|
|
entries.push({ message: context.initializers[guid] });
|
2021-07-01 14:31:20 -07:00
|
|
|
}
|
2023-02-27 15:29:20 -08:00
|
|
|
if (event.method === 'pageError')
|
|
|
|
|
entries.push({ error: event.params.error });
|
2021-07-01 14:31:20 -07:00
|
|
|
}
|
|
|
|
|
return entries;
|
2021-07-01 20:46:56 -07:00
|
|
|
}, [action]);
|
2021-07-01 14:31:20 -07:00
|
|
|
|
|
|
|
|
return <div className='console-tab'>{
|
|
|
|
|
entries.map((entry, index) => {
|
|
|
|
|
const { message, error } = entry;
|
|
|
|
|
if (message) {
|
|
|
|
|
const url = message.location.url;
|
|
|
|
|
const filename = url ? url.substring(url.lastIndexOf('/') + 1) : '<anonymous>';
|
|
|
|
|
return <div className={'console-line ' + message.type} key={index}>
|
|
|
|
|
<span className='console-location'>{filename}:{message.location.lineNumber}</span>
|
|
|
|
|
<span className={'codicon codicon-' + iconClass(message)}></span>
|
|
|
|
|
<span className='console-line-message'>{message.text}</span>
|
|
|
|
|
</div>;
|
|
|
|
|
}
|
|
|
|
|
if (error) {
|
|
|
|
|
const { error: errorObject, value } = error;
|
|
|
|
|
if (errorObject) {
|
|
|
|
|
return <div className='console-line error' key={index}>
|
|
|
|
|
<span className={'codicon codicon-error'}></span>
|
|
|
|
|
<span className='console-line-message'>{errorObject.message}</span>
|
|
|
|
|
<div className='console-stack'>{errorObject.stack}</div>
|
|
|
|
|
</div>;
|
|
|
|
|
} else {
|
|
|
|
|
return <div className='console-line error' key={index}>
|
|
|
|
|
<span className={'codicon codicon-error'}></span>
|
2022-06-06 21:05:47 -07:00
|
|
|
<span className='console-line-message'>{String(value)}</span>
|
2021-07-01 14:31:20 -07:00
|
|
|
</div>;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
})
|
|
|
|
|
}</div>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function iconClass(message: channels.ConsoleMessageInitializer): string {
|
|
|
|
|
switch (message.type) {
|
|
|
|
|
case 'error': return 'error';
|
|
|
|
|
case 'warning': return 'warning';
|
|
|
|
|
}
|
|
|
|
|
return 'blank';
|
|
|
|
|
}
|