siyuan-note/siyuan · error

save OAuth client registration: %w

Error message

save OAuth client registration: %w

What it means

Wrapped error at oauth.go:334-335 when putOAuthCredential fails to persist the freshly registered client credential (client_id, secret, endpoints, scopes). The registration itself succeeded but local storage (keystore backing oauthCredential) rejected the write.

Source

Thrown at kernel/mcp/client/oauth.go:335

			ClientSecret:        registration.ClientSecret,
			ClientSecretExpiry:  registration.ClientSecretExpiresAt,
			TokenEndpoint:       asm.TokenEndpoint,
			RevocationEndpoint:  asm.RevocationEndpoint,
			TokenAuthMethod:     registration.TokenEndpointAuthMethod,
			Scopes:              scopes,
		}
		if registrationCredential.TokenAuthMethod == "" {
			if registration.ClientSecret == "" {
				registrationCredential.TokenAuthMethod = "none"
			} else {
				registrationCredential.TokenAuthMethod = "client_secret_basic"
			}
		}
		if !isSupportedTokenAuthMethod(registrationCredential.TokenAuthMethod) {
			return fmt.Errorf("OAuth client registration returned an unsupported token endpoint authentication method")
		}
		if err = putOAuthCredential(registrationCredential); err != nil {
			return fmt.Errorf("save OAuth client registration: %w", err)
		}
	}

	authMethod := registrationCredential.TokenAuthMethod
	if authMethod == "" {
		if registrationCredential.ClientSecret == "" {
			authMethod = "none"
		} else {
			authMethod = "client_secret_basic"
		}
	}
	config := &oauth2.Config{
		ClientID:     registrationCredential.ClientID,
		ClientSecret: registrationCredential.ClientSecret,
		RedirectURL:  callbackURL,
		Scopes:       scopes,
		Endpoint: oauth2.Endpoint{
			AuthURL:   asm.AuthorizationEndpoint,

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Check the wrapped error (file system errno) and free space / fix permissions on the kernel data directory.
  2. Ensure no other SiYuan process holds the workspace lock (single-instance requirement).
  3. Retry the authorization once the storage issue is resolved; the AS registration is still valid until it expires, but SiYuan must re-register because the save failed.
Defensive patterns

Strategy: try-catch

Try / catch

if err = putOAuthCredential(registrationCredential); err != nil {
    // Error 327: registration succeeded locally but persistence failed.
    logging.LogErrorf("mcp oauth: persist registration failed: %s", err)
    return fmt.Errorf("save OAuth client registration: %w", err)
}

Prevention

When it happens

Trigger: putOAuthCredential returns a non-nil error immediately after a successful RegisterClient and the TokenAuthMethod validation passed. Subsequent calls will re-attempt registration because nothing was saved.

Common situations: Disk full or permission denied on the keystore file; workspace data directory not writable; keystore JSON corruption that fails to serialize; antivirus/file-lock on Windows locking the credential file.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/3512a79dc8c2fb28. Report an issue: GitHub.