jlcodes99/cockpit-tools · warning

[Announcement] 未支持的命令动作:

Error message

[Announcement] 未支持的命令动作:

What it means

In AnnouncementCenter's runAction switch, each announcement command action has a target that maps to a known branch (navigation, link, etc.). When action.target holds a value with no matching case, the default branch logs this warning. The detail panel still closes via closeDetail(false), but the announced action does nothing.

Source

Thrown at src/components/AnnouncementCenter.tsx:298

      switch (action.target) {
        case 'update.check': {
          window.dispatchEvent(new CustomEvent('update-check-requested', { detail: { source: 'manual' } }));
          break;
        }
        case 'announcement.forceRefresh': {
          await fetchState(true);
          break;
        }
        case 'page.navigate': {
          const target = typeof action.arguments?.[0] === 'string' ? action.arguments[0] : '';
          const targetPage = target ? TAB_TARGET_PAGE_MAP[target] : undefined;
          if (targetPage) {
            onNavigate(targetPage);
          }
          break;
        }
        default:
          console.warn('[Announcement] 未支持的命令动作:', action.target);
      }
      await closeDetail(false);
    }
  };

  const currentTypeLabel = (type: string) => {
    if (type === 'feature') return t('announcement.type.feature', '✨ 新功能');
    if (type === 'warning') return t('announcement.type.warning', '⚠️ 警告');
    if (type === 'urgent') return t('announcement.type.urgent', '🚨 紧急');
    return t('announcement.type.info', 'ℹ️ 信息');
  };

  const renderInBody = (node: ReactNode) => {
    if (typeof document === 'undefined') {
      return node;
    }
    return createPortal(node, document.body);
  };

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Log/inspect the printed action.target value to see the unknown action name.
  2. Update the app — the target type is likely from a newer release than this build.
  3. Fix the announcement content in the management backend if the target is misspelled.
  4. Add a case for the new target in runAction's switch if you own the code.

Example fix

// before
default:
  console.warn('[Announcement] 未支持的命令动作:', action.target);
// after
default:
  console.warn('[Announcement] 未支持的命令动作:', action.target);
  assertNever(action.target); // compile-time check when new targets are added to the union
Defensive patterns

Strategy: type-guard

Validate before calling

const KNOWN_ACTION_TARGETS = ['navigate', 'open_url', 'dismiss'] as const;
type ActionTarget = typeof KNOWN_ACTION_TARGETS[number];
if (!KNOWN_ACTION_TARGETS.includes(action.target as ActionTarget)) {
  console.warn('[Announcement] 未支持的命令动作:', action.target);
  return;
}

Type guard

function isKnownActionTarget(t: string): t is ActionTarget {
  return (['navigate', 'open_url', 'dismiss'] as const).includes(t as ActionTarget);
}

Try / catch

switch (action.target) {
  // ...known cases...
  default: {
    console.warn('[Announcement] 未支持的命令动作:', action.target);
    break; // no-op but still close detail panel
  }
}
await closeDetail(false);

Prevention

When it happens

Trigger: Clicking a call-to-action on an announcement whose action.target is an unrecognized string: a new target type introduced by a newer backend/app version, a typo in the announcement content, or content authored against a different schema.

Common situations: Announcements pushed by a newer backend using a target type this app build doesn't know yet; CMS-managed announcement copy with a misspelled target; stale cached announcements after an app downgrade.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/a66abb5a2e3d2315. Report an issue: GitHub.