toeverything/AFFiNE · error · InvalidLicenseToActivate

invalid_license_to_activate

invalid_license_to_activate

Error message

Invalid license to activate. Invalid license.

What it means

previewLicense() resolves an uploaded license buffer without persisting it, to show the admin what would be installed. It throws InvalidLicenseToActivate with reason 'Invalid license.' when the resolver reports an invalid entitlement — i.e. signature/structure verification failed rather than a clean expiry or workspace mismatch, which have their own dedicated throws inside resolveWorkspaceTeamLicense. This branch is the defensive catch-all of the preview flow.

Source

Thrown at packages/backend/server/src/plugins/license/service.ts:169

      expiresAt: this.licenseExpiresAt(resolved),
      validatedAt,
      variant: SubscriptionVariant.Onetime,
      license,
    });
    await this.event.emitAsync('workspace.subscription.activated', {
      workspaceId,
      plan: SubscriptionPlan.SelfHostedTeam,
      recurring: this.licenseRecurring(resolved),
      quantity: this.licenseQuantity(resolved),
    });

    return installed;
  }

  previewLicense(license: Buffer): LicensePreview {
    const resolved = this.resolveWorkspaceTeamLicense(null, license);
    if (!resolved.valid) {
      throw new InvalidLicenseToActivate({
        reason: 'Invalid license.',
      });
    }
    const expiresAt = this.licenseExpiresAt(resolved);

    return {
      id: this.licenseSubjectId(resolved),
      workspaceId: this.licenseWorkspaceId(resolved),
      plan: SubscriptionPlan.SelfHostedTeam,
      recurring: this.licenseRecurring(resolved),
      quantity: this.licenseQuantity(resolved),
      issuedAt: new Date(resolved.issuedAt ?? ''),
      expiresAt,
      endAt: expiresAt,
      entity: resolved.entity ?? '',
      issuer: resolved.issuer ?? '',
      valid: true,
    };

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Re-download the license file from https://app.affine.pro and upload it unmodified.
  2. Confirm you are uploading the binary license (usually .license file), not the order confirmation or invoice.
  3. Verify checksum/size against the source if corruption is suspected; if it still fails, the file may be for a different product line — request a reissue from Affine support.
Defensive patterns

Strategy: try-catch

Validate before calling

const LICENSE_MAGIC = 0x41; // inspect first bytes / expected file shape before upload
function looksLikeLicenseFile(buf: Buffer): boolean {
  return buf.length > 0 && buf.length < 1_000_000; // reject obvious wrong files (PDF/HTML)
}

Type guard

function isInvalidLicenseToActivate(e: unknown): e is InvalidLicenseToActivate {
  return e instanceof InvalidLicenseToActivate;
}

Try / catch

try {
  const preview = licenseService.previewLicense(licenseBuffer);
} catch (e) {
  if (e instanceof InvalidLicenseToActivate) {
    // surface e.extensions.reason to the uploader ('Invalid license.' → re-download the file)
  } else throw e;
}

Prevention

When it happens

Trigger: Calling previewLicense(licenseBuffer) with a truncated download, a file that is not an AFFiNE Pro license at all (e.g. an EULA PDF or JSON), a license signed for a different key scheme, or bytes corrupted in transit/base64 decoding.

Common situations: Admin uploads the wrong file from the license email; CI tests feed arbitrary buffers; license file edited by hand or re-saved with encoding changes (BOM, CRLF); browser 'save page' instead of raw download.

Related errors


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/5e1027b813e800a5. Report an issue: GitHub.