mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-07-21 09:03:06 +02:00
#777 - Show error when front matter parsing failed
This commit is contained in:
@@ -28,7 +28,7 @@ import {
|
||||
SETTING_TAXONOMY_CONTENT_TYPES
|
||||
} from '../../constants';
|
||||
import { Article, Preview } from '../../commands';
|
||||
import { ParsedFrontMatter } from '../../parsers';
|
||||
import { FrontMatterParser, ParsedFrontMatter } from '../../parsers';
|
||||
import { Field, Mode, PostMessageData, ContentType as IContentType } from '../../models';
|
||||
import { encodeEmoji, fieldWhenClause } from '../../utils';
|
||||
import { PanelProvider } from '../../panelWebView/PanelProvider';
|
||||
@@ -198,6 +198,26 @@ export class DataListener extends BaseListener {
|
||||
try {
|
||||
if (filePath) {
|
||||
articleDetails = await ArticleHelper.getDetails(filePath);
|
||||
|
||||
if (!articleDetails) {
|
||||
try {
|
||||
const contents = await ArticleHelper.getContents(filePath);
|
||||
if (contents) {
|
||||
FrontMatterParser.fromFile(contents);
|
||||
}
|
||||
} catch (e) {
|
||||
this.sendMsg(Command.metadata, {
|
||||
fmError: l10n.t(
|
||||
LocalizationKey.listenersPanelDataListenerPushMetadataFrontMatterError
|
||||
),
|
||||
fmErrorMessage: (e as Error).message
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.sendMsg(Command.metadata, undefined);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.error(`DataListener::pushMetadata: ${(e as Error).message}`);
|
||||
|
||||
@@ -1504,6 +1504,10 @@ export enum LocalizationKey {
|
||||
* Metadata
|
||||
*/
|
||||
panelMetadataTitle = 'panel.metadata.title',
|
||||
/**
|
||||
* Check the output for more information
|
||||
*/
|
||||
panelMetadataFocusProblems = 'panel.metadata.focusProblems',
|
||||
/**
|
||||
* Other actions
|
||||
*/
|
||||
@@ -2536,6 +2540,10 @@ export enum LocalizationKey {
|
||||
* Couldn't find data file entries
|
||||
*/
|
||||
listenersPanelDataListenerGetDataFileEntriesNoDataFilesError = 'listeners.panel.dataListener.getDataFileEntries.noDataFiles.error',
|
||||
/**
|
||||
* Something went wrong while parsing your front matter. Please check the contents of your file.
|
||||
*/
|
||||
listenersPanelDataListenerPushMetadataFrontMatterError = 'listeners.panel.dataListener.pushMetadata.frontMatter.error',
|
||||
/**
|
||||
* No active editor
|
||||
*/
|
||||
|
||||
@@ -86,7 +86,7 @@ export const ViewPanel: React.FunctionComponent<IViewPanelProps> = (
|
||||
return <Spinner />;
|
||||
}
|
||||
|
||||
if (!metadata || Object.keys(metadata || {}).length === 0) {
|
||||
if (!metadata) {
|
||||
return <BaseView mode={mode} settings={settings} folderAndFiles={folderAndFiles} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import useContentType from '../../hooks/useContentType';
|
||||
import { WrapperField } from './Fields/WrapperField';
|
||||
import { ContentTypeValidator } from './ContentType/ContentTypeValidator';
|
||||
import { FeatureFlag } from '../../components/features/FeatureFlag';
|
||||
import { FEATURE_FLAG } from '../../constants';
|
||||
import { FEATURE_FLAG, GeneralCommands } from '../../constants';
|
||||
import { Messenger } from '@estruyf/vscode/dist/client';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
import { LocalizationKey } from '../../localization';
|
||||
@@ -33,6 +33,12 @@ const Metadata: React.FunctionComponent<IMetadataProps> = ({
|
||||
}: React.PropsWithChildren<IMetadataProps>) => {
|
||||
const contentType = useContentType(settings, metadata);
|
||||
|
||||
const focusProblems = () => {
|
||||
Messenger.send(GeneralCommands.toVSCode.runCommand, {
|
||||
command: `workbench.panel.markers.view.focus`
|
||||
});
|
||||
}
|
||||
|
||||
const onSendUpdate = React.useCallback((field: string | undefined, value: any, parents: string[]) => {
|
||||
if (!field) {
|
||||
return;
|
||||
@@ -93,7 +99,20 @@ const Metadata: React.FunctionComponent<IMetadataProps> = ({
|
||||
<ContentTypeValidator fields={contentType?.fields || []} metadata={metadata} />
|
||||
</FeatureFlag>
|
||||
|
||||
{allFields}
|
||||
{
|
||||
metadata.fmError && metadata.fmErrorMessage ? (
|
||||
<div className={`space-y-4`}>
|
||||
<p className={`text-[var(--vscode-errorForeground)]`}>{metadata.fmError}</p>
|
||||
|
||||
<button
|
||||
title={l10n.t(LocalizationKey.panelMetadataFocusProblems)}
|
||||
onClick={focusProblems}
|
||||
type={`button`}>
|
||||
{l10n.t(LocalizationKey.panelMetadataFocusProblems)}
|
||||
</button>
|
||||
</div>
|
||||
) : allFields
|
||||
}
|
||||
</Collapsible>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user