TencentCloud/TencentDB-Agent-Memory · error · SkillCoreError

SkillCoreError rethrow with translated code (message preserv

Error message

SkillCoreError rethrow with translated code (message preserved from lower layer)

What it means

toCoreError is the SkillCore error-translation boundary: any error thrown by a lower layer (store, versioning, fs) that carries a "code" property is re-wrapped as a SkillCoreError with that code while preserving the original message. The generic message here describes that rethrow — you see the ORIGINAL lower-layer message inside a SkillCoreError wrapper, so the root cause is whatever message accompanies it.

Source

Thrown at MemoryCore/src/core/skill/skill-core.ts:87

  | "STORAGE_NOT_FOUND"
  | "LLM_UNAVAILABLE"
  | "SKILL_COS_REQUIRED"
  | "SKILL_EXPORT_TOO_LARGE";

export class SkillCoreError extends Error {
  constructor(public readonly code: SkillCoreErrorCode, message?: string) {
    super(message ? `${code}: ${message}` : code);
    this.name = "SkillCoreError";
  }
}

// 工具:把下层抛的各类错误统一翻译为 SkillCoreError(保留原 message)
function toCoreError(e: unknown): never {
  if (e instanceof SkillCoreError) throw e;
  const code = (e as { code?: string }).code as SkillCoreErrorCode | undefined;
  const msg = (e as Error).message;
  if (code) {
    throw new SkillCoreError(code, msg);
  }
  throw e as Error;
}

// ═════════════════════════════════════════════════════════════════════
//  Options
// ═════════════════════════════════════════════════════════════════════

export interface SkillCoreOptions {
  store: ISkillStore;
  resources: SkillResourceStore;
  versioning: SkillVersioning;
  /**
   * 用于 skill_id 生成。默认 `skl-` + 12 字符 base62(CSPRNG,71 bit 真熵)。
   * 保持与老 sid 相同长度 (16 字符),仅字符集从 base36 扩到 base62 且用真随机源。
   * 测试可注入固定值。
   */
  ulid?: () => string;

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Read the preserved message (and original code) in the thrown SkillCoreError to find the real lower-layer failure
  2. Handle the specific SkillCoreErrorCode in your catch (e.g. retry on transient store errors, surface validation codes to callers)
  3. If the code translation is wrong for your backend, fix the mapping in toCoreError or normalize codes at the adapter boundary
  4. Log the original error stack before wrapping so the lower-layer origin is traceable
Defensive patterns

Strategy: try-catch

Validate before calling

// no pre-call validation applies; prepare classification for wrapped errors
function unwrapSkillCoreError(e: unknown): { code?: string; message: string } | null {
  if (e instanceof SkillCoreError) return { code: e.code, message: e.message };
  return null;
}

Type guard

function isSkillCoreError(e: unknown): e is SkillCoreError {
  return e instanceof SkillCoreError && typeof e.code === "string";
}

Try / catch

try {
  await core.create(input);
} catch (e) {
  if (isSkillCoreError(e)) {
    switch (e.code) {
      case "STORE_UNAVAILABLE": return retryWithBackoff();
      case "INVALID_FRONTMATTER": return reportValidation(e.message);
      default: logger.error({ code: e.code, msg: e.message }, "lower-layer failure surfaced via toCoreError");
    }
  }
  throw e;
}

Prevention

When it happens

Trigger: Any call into store/versioning from create, update, patch, writeFiles, or removeFiles that throws a coded, non-SkillCoreError — e.g. the persistence layer throwing {code: "STORE_UNAVAILABLE", message: ...} or an fs adapter with its own error codes.

Common situations: Backend store outages or constraint violations surfacing with their native codes; versioning layer rejecting appends; integration points where a dependency's error contract changed and its codes now map to a different SkillCoreErrorCode than before.


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/9e545fcb095c0cef. Report an issue: GitHub.