# Wiki.macro.cancelEdit

URL: https://docs.ones.cn/developer/abilities/web-sdk/wiki-macro-cancel-edit

Cancel macro editing, restore configuration, resource references and static content to their pre-session values, and release the collaboration lock.

## Requirements

| ONES | `@ones-open/web-sdk` |
| --- | --- |
| `7.45.0+` | `0.0.20+` |

Declare and enable a [Wiki custom macro](https://docs.ones.cn/developer/abilities/extensions/wiki-macro/) . Each method targets the calling entry's macro instance and does not accept another macro's ID. Public sharing, mobile and search do not load the macro runtime and cannot call these methods.

## Signature

```ts
interface MacroAPI {
  cancelEdit(): Promise<void>
}
```

## Parameters

No parameters. Do not supply restore data, callbacks or macro IDs; the Wiki edit session manages restoration.

## Returns and behavior

`Promise<void>` resolves when restoration and session termination are confirmed. Wiki then closes the edit entry.

Call only from an active edit entry. Confirmed `saveData` calls in the same session are also reverted. Independent backend business writes are not rolled back. Uploaded files are not physically deleted; the macro's resource references are restored.

The Wiki dialog close button, Esc and backdrop invoke cancellation. Leaving a page or losing a session differs from explicit cancellation; see [collaborative editing](https://docs.ones.cn/developer/abilities/extensions/wiki-macro/#collaborative-editing) .

## Errors

| Error code | Meaning and trigger | Recommended handling |
| --- | --- | --- |
| `READ_ONLY` | Called from the render entry, or the macro is no longer writable, edit permission was lost or login credentials are unavailable. | Do not report cancellation as successful; verify page and session state after restoring access. |
| `SESSION_EXPIRED` | The edit session is missing, finished or expired, or the editor was destroyed while waiting for collaboration updates. | Read current macro content and check what is actually saved; do not assume previous content was restored. |
| `RESOURCE_NOT_ACCESSIBLE` | The pre-session content references resources that the current document can no longer read, so restoration fails resource validation. | Check missing or invalid resources; do not mark the content as restored. |
| `REVISION_CONFLICT` | The macro revision differs from the session record during restoration, or another operation changed session state. | Read current macro content and review differences; do not force an overwrite. |
| `COMMIT_UNKNOWN` | A previous save or this cancellation is unconfirmed, or the browser has not received the collaboration revision for restored content. | Keep current state and retry `cancelEdit` to confirm the original operation; do not switch to finishing or open another session. |
| `CARD_UPDATE_FAILED` | Macro content in the document has been restored, but card static content could not be restored in sync, or required card information is missing. | Retry `cancelEdit` to complete synchronization; do not report full restoration before success. |
| `MACRO_UNAVAILABLE` | The runtime, macro block, app or a dependency is unavailable, or macro availability authorization failed. | Verify page and session state after recovery before continuing. |

`cancelEdit` first confirms an already sent pending save, then restores pre-session content. It can therefore also return that save's validation or resource errors; see the [`saveData` error table](https://docs.ones.cn/developer/abilities/web-sdk/wiki-macro-save-data/#errors) for their meaning. Catch failures with `try / catch` ; see [Catching errors](https://docs.ones.cn/developer/abilities/web-sdk/wiki-macro-types/#calling-and-catching-errors) for the error object contract.

## Examples

### Install via package manager

```ts
import { Wiki } from '@ones-open/web-sdk'

async function cancelConfiguration() {
  try {
    await Wiki.macro.cancelEdit()
  } catch (error) {
    console.error(error)
  }
}
```

### Use via external script

```html
<script src="https://unpkg.com/@ones-open/web-sdk@0.0.20/dist/index.iife.js"></script>
<script>
  ;(async function () {
    await window.SDK.Wiki.macro.cancelEdit()
  })().catch(console.error)
</script>
```

## Related documentation

- [Macro types and fields](https://docs.ones.cn/developer/abilities/web-sdk/wiki-macro-types/)
- [ONES.getExtensionContext](https://docs.ones.cn/developer/abilities/web-sdk/get-extension-context/)
- [Wiki custom macro capability](https://docs.ones.cn/developer/abilities/extensions/wiki-macro/)
