

























@@ -16,6 +16,7 @@ import {
1616resolveSetupChannelRegistration,
1717} from "../../plugins/loader-channel-setup.js";
1818import type { PluginManifestRecord } from "../../plugins/manifest-registry.js";
19+import type { PluginDiagnostic } from "../../plugins/manifest-types.js";
1920import { loadPluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js";
2021import {
2122getCachedPluginModuleLoader,
@@ -61,6 +62,7 @@ type PluginLoaderModule = {
6162pluginId: string;
6263plugin: ChannelPlugin;
6364}>;
65+diagnostics?: readonly PluginDiagnostic[];
6466};
6567};
6668@@ -131,8 +133,15 @@ type ReadOnlyChannelPluginResolution = {
131133plugins: ChannelPlugin[];
132134configuredChannelIds: string[];
133135missingConfiguredChannelIds: string[];
136+loadFailures: ReadOnlyChannelPluginLoadFailure[];
134137};
135138type ManifestChannelConfigRecord = NonNullable<PluginManifestRecord["channelConfigs"]>[string];
139+export type ReadOnlyChannelPluginLoadFailure = {
140+channelId: string;
141+pluginId: string;
142+message: string;
143+source?: string;
144+};
136145137146function addChannelPlugins(
138147byId: Map<string, ChannelPlugin>,
@@ -378,9 +387,9 @@ export { resolveReadOnlyChannelCommandDefaults };
378387function loadSetupChannelPluginFromManifestRecord(params: {
379388record: PluginManifestRecord;
380389channelId: string;
381-}): ChannelPlugin | undefined {
390+}): { plugin?: ChannelPlugin; failure?: ReadOnlyChannelPluginLoadFailure } {
382391if (!params.record.setupSource || !params.record.channels.includes(params.channelId)) {
383-return undefined;
392+return {};
384393}
385394try {
386395const moduleLoader = getCachedPluginModuleLoader({
@@ -393,8 +402,18 @@ function loadSetupChannelPluginFromManifestRecord(params: {
393402cacheScopeKey: "read-only-setup-entry",
394403});
395404const registration = resolveSetupChannelRegistration(moduleLoader(params.record.setupSource));
405+if (registration.loadError) {
406+return {
407+failure: {
408+channelId: params.channelId,
409+pluginId: params.record.id,
410+source: params.record.setupSource,
411+message: `failed to load setup entry: ${formatErrorMessage(registration.loadError)}`,
412+},
413+};
414+}
396415if (!registration.plugin) {
397-return undefined;
416+return {};
398417}
399418if (
400419!channelPluginIdBelongsToManifest({
@@ -403,14 +422,55 @@ function loadSetupChannelPluginFromManifestRecord(params: {
403422manifestChannels: params.record.channels,
404423})
405424) {
406-return undefined;
425+return {};
407426}
408-return cloneChannelPluginForChannelId(registration.plugin, params.channelId);
427+return { plugin: cloneChannelPluginForChannelId(registration.plugin, params.channelId) };
409428} catch (error) {
410429const detail = formatErrorMessage(error);
411430log.warn(`[channels] failed to load channel setup ${params.record.id}: ${detail}`);
412-return undefined;
431+return {
432+failure: {
433+channelId: params.channelId,
434+pluginId: params.record.id,
435+source: params.record.setupSource,
436+message: `failed to load setup entry: ${detail}`,
437+},
438+};
439+}
440+}
441+442+function collectChannelPluginLoadFailuresFromDiagnostics(params: {
443+diagnostics: readonly PluginDiagnostic[] | undefined;
444+records: readonly PluginManifestRecord[];
445+channelIds: readonly string[];
446+}): ReadOnlyChannelPluginLoadFailure[] {
447+if (!params.diagnostics?.length || params.channelIds.length === 0) {
448+return [];
413449}
450+const configuredChannelIds = new Set(params.channelIds);
451+const recordsByPluginId = new Map(params.records.map((record) => [record.id, record] as const));
452+const failures: ReadOnlyChannelPluginLoadFailure[] = [];
453+for (const diagnostic of params.diagnostics) {
454+if (diagnostic.level !== "error" || !diagnostic.pluginId) {
455+continue;
456+}
457+const record = recordsByPluginId.get(diagnostic.pluginId);
458+if (!record) {
459+continue;
460+}
461+for (const channelId of record.channels) {
462+if (!configuredChannelIds.has(channelId)) {
463+continue;
464+}
465+failures.push({
466+ channelId,
467+pluginId: record.id,
468+source: diagnostic.source,
469+message: diagnostic.message,
470+});
471+}
472+}
473+return failures;
414474}
415475416476function rebindChannelPluginConfig(
@@ -730,6 +790,7 @@ export function resolveReadOnlyChannelPluginsForConfig(
730790),
731791].filter(isSafeManifestChannelId);
732792const byId = new Map<string, ChannelPlugin>();
793+const loadFailures: ReadOnlyChannelPluginLoadFailure[] = [];
733794734795addChannelPlugins(byId, listChannelPlugins());
735796@@ -738,16 +799,22 @@ export function resolveReadOnlyChannelPluginsForConfig(
738799if (byId.has(channelId)) {
739800continue;
740801}
802+const setupResults = bundledManifestRecords
803+.filter((record) => record.channels.includes(channelId))
804+.map((record) =>
805+loadSetupChannelPluginFromManifestRecord({
806+ record,
807+ channelId,
808+}),
809+);
810+loadFailures.push(
811+ ...setupResults
812+.map((result) => result.failure)
813+.filter((failure): failure is ReadOnlyChannelPluginLoadFailure => Boolean(failure)),
814+);
741815const bundledSetupPlugin =
742-bundledManifestRecords
743-.filter((record) => record.channels.includes(channelId))
744-.map((record) =>
745-loadSetupChannelPluginFromManifestRecord({
746- record,
747- channelId,
748-}),
749-)
750-.find((plugin) => plugin) ?? getBundledChannelSetupPlugin(channelId, env);
816+setupResults.map((result) => result.plugin).find((plugin) => plugin) ??
817+getBundledChannelSetupPlugin(channelId, env);
751818addChannelPlugins(byId, [bundledSetupPlugin]);
752819}
753820}
@@ -803,6 +870,13 @@ export function resolveReadOnlyChannelPluginsForConfig(
803870requireSetupEntryForSetupOnlyChannelPlugins: true,
804871onlyPluginIds: externalPluginIds,
805872});
873+loadFailures.push(
874+ ...collectChannelPluginLoadFailuresFromDiagnostics({
875+diagnostics: registry.diagnostics,
876+records: externalManifestRecords,
877+channelIds: missingConfiguredChannelIds,
878+}),
879+);
806880addSetupChannelPlugins(byId, registry.channelSetups, {
807881 ownedChannelIdsByPluginId,
808882 ownedMissingChannelIdsByPluginId,
@@ -822,5 +896,6 @@ export function resolveReadOnlyChannelPluginsForConfig(
822896 plugins,
823897 configuredChannelIds,
824898missingConfiguredChannelIds: configuredChannelIds.filter((channelId) => !byId.has(channelId)),
899+ loadFailures,
825900};
826901}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。