Fix promise error handling and improve rename docs

- Add catch {} for promise.reject/resolve in finalize() (API change)
- Expand Bun.rename() docs with function signature and conflict mode table

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-28 21:26:00 +00:00
parent f57454afea
commit fad01ae8d8
2 changed files with 12 additions and 2 deletions

View File

@@ -154,6 +154,8 @@ await Bun.write("index.html", response);
## Renaming files (`Bun.rename()`)
`Bun.rename(from, to, conflict?): Promise<void>`
Atomically rename or move files and directories. Similar to Node.js `fs.promises.rename()` but with an optional third parameter for conflict resolution.
```ts
@@ -167,6 +169,14 @@ await Bun.rename("file1.txt", "file2.txt", "swap");
await Bun.rename("source.txt", "dest.txt", "no-replace");
```
The `conflict` parameter controls behavior when the destination already exists:
| Mode | Description |
| ---- | ----------- |
| `"replace"` | Replace destination if it exists (default) |
| `"swap"` | Atomically swap the two files (Linux/macOS only, falls back to `"replace"` on Windows) |
| `"no-replace"` | Fail with an error if destination exists |
---
## Incremental writing with `FileSink`

View File

@@ -840,10 +840,10 @@ const RenameJob = struct {
.err => |*err| {
defer err.deinit();
const error_instance = globalThis.createErrorInstance("rename failed: errno {d}", .{err.errno});
promise.reject(globalThis, error_instance);
promise.reject(globalThis, error_instance) catch {};
},
.result => {
promise.resolve(globalThis, jsc.JSValue.js_undefined);
promise.resolve(globalThis, jsc.JSValue.js_undefined) catch {};
},
}